pub unsafe trait Castable { }Expand description
Marker trait for castable data.
This trait is important to maintain the defined integrity of casting
against buffers of bytes. There are lots of opportunity for undefined
behavior to happen. By implementing an object as Castable, you are
declaring the following:
- The type is inhabited (e.g., no Infallible).
- The type allows any bit pattern (e.g., no
boolorchar). - The type does not contain any padding bytes.
- The type’s members are also
Castable. - The type is
#[repr(C)],#[repr(transparent)],#[repr(packed)]or#[repr(align)]. - The type must not use generics.
If you’ve used the bytemuck library, these rules will probably seem familiar. You can automatically guarantee these traits of your data with the Castable derive macro.
Implementations on Foreign Types§
impl Castable for f32
impl Castable for f64
impl Castable for i8
impl Castable for i16
impl Castable for i32
impl Castable for i64
impl Castable for i128
impl Castable for isize
impl Castable for u8
impl Castable for u16
impl Castable for u32
impl Castable for u64
impl Castable for u128
impl Castable for ()
impl Castable for usize
impl Castable for __m128
Available on x86 only.
impl Castable for __m128d
Available on x86 only.
impl Castable for __m128i
Available on x86 only.
impl Castable for __m256
Available on x86 only.
impl Castable for __m256d
Available on x86 only.
impl Castable for __m256i
Available on x86 only.