]>
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 { | |
22 | debug_assert!( | |
23 | crate::mem::size_of::<Self>() == crate::mem::size_of::<U>() | |
24 | ); | |
25 | U::from_bits(self) | |
26 | } | |
27 | } | |
28 | ||
29 | /// `FromBits` and `IntoBits` are reflexive | |
30 | impl<T> FromBits<T> for T { | |
31 | #[inline] | |
32 | fn from_bits(t: Self) -> Self { | |
33 | t | |
34 | } | |
35 | } | |
36 | ||
37 | #[macro_use] | |
38 | mod macros; | |
39 | ||
40 | mod v16; | |
41 | pub use self::v16::*; | |
42 | ||
43 | mod v32; | |
44 | pub use self::v32::*; | |
45 | ||
46 | mod v64; | |
47 | pub use self::v64::*; | |
48 | ||
49 | mod v128; | |
50 | pub use self::v128::*; | |
51 | ||
52 | mod v256; | |
53 | pub use self::v256::*; | |
54 | ||
55 | mod v512; | |
56 | pub use self::v512::*; | |
57 | ||
58 | mod arch_specific; | |
59 | pub use self::arch_specific::*; |