]> git.proxmox.com Git - rustc.git/blame - vendor/packed_simd_2/src/api/into_bits.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / vendor / packed_simd_2 / src / api / into_bits.rs
CommitLineData
f20569fa
XL
1//! Implementation of `FromBits` and `IntoBits`.
2
3/// Safe lossless bitwise conversion from `T` to `Self`.
4pub 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`.
10pub 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`.
16impl<T, U> IntoBits<U> for T
17where
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
28impl<T> FromBits<T> for T {
29 #[inline]
30 fn from_bits(t: Self) -> Self {
31 t
32 }
33}
34
35#[macro_use]
36mod macros;
37
38mod v16;
39pub use self::v16::*;
40
41mod v32;
42pub use self::v32::*;
43
44mod v64;
45pub use self::v64::*;
46
47mod v128;
48pub use self::v128::*;
49
50mod v256;
51pub use self::v256::*;
52
53mod v512;
54pub use self::v512::*;
55
56mod arch_specific;
57pub use self::arch_specific::*;