]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | //! Implementation of `FromBits` and `IntoBits`. |
2 | ||
3 | /// Safe lossless bitwise conversion from `T` to `Self`. | |
4 | pub trait FromBits<T>: crate::marker::Sized { | |
5 | /// Safe lossless bitwise transmute from `T` to `Self`. | |
6 | fn from_bits(t: T) -> Self; | |
7 | } | |
8 | ||
9 | /// Safe lossless bitwise conversion from `Self` to `T`. | |
10 | pub trait IntoBits<T>: crate::marker::Sized { | |
11 | /// Safe lossless bitwise transmute from `self` to `T`. | |
12 | fn into_bits(self) -> T; | |
13 | } | |
14 | ||
15 | /// `FromBits` implies `IntoBits`. | |
16 | impl<T, U> IntoBits<U> for T | |
17 | where | |
18 | U: FromBits<T>, | |
19 | { | |
20 | #[inline] | |
21 | fn into_bits(self) -> U { | |
f25598a0 | 22 | debug_assert!(crate::mem::size_of::<Self>() == crate::mem::size_of::<U>()); |
f20569fa XL |
23 | U::from_bits(self) |
24 | } | |
25 | } | |
26 | ||
27 | /// `FromBits` and `IntoBits` are reflexive | |
28 | impl<T> FromBits<T> for T { | |
29 | #[inline] | |
30 | fn from_bits(t: Self) -> Self { | |
31 | t | |
32 | } | |
33 | } | |
34 | ||
35 | #[macro_use] | |
36 | mod macros; | |
37 | ||
38 | mod v16; | |
39 | pub use self::v16::*; | |
40 | ||
41 | mod v32; | |
42 | pub use self::v32::*; | |
43 | ||
44 | mod v64; | |
45 | pub use self::v64::*; | |
46 | ||
47 | mod v128; | |
48 | pub use self::v128::*; | |
49 | ||
50 | mod v256; | |
51 | pub use self::v256::*; | |
52 | ||
53 | mod v512; | |
54 | pub use self::v512::*; | |
55 | ||
56 | mod arch_specific; | |
57 | pub use self::arch_specific::*; |