Castable

Trait Castable 

Source
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 bool or char).
  • 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§

Source§

impl Castable for f32

Source§

impl Castable for f64

Source§

impl Castable for i8

Source§

impl Castable for i16

Source§

impl Castable for i32

Source§

impl Castable for i64

Source§

impl Castable for i128

Source§

impl Castable for isize

Source§

impl Castable for u8

Source§

impl Castable for u16

Source§

impl Castable for u32

Source§

impl Castable for u64

Source§

impl Castable for u128

Source§

impl Castable for ()

Source§

impl Castable for usize

Source§

impl Castable for __m128

Available on x86 only.
Source§

impl Castable for __m128d

Available on x86 only.
Source§

impl Castable for __m128i

Available on x86 only.
Source§

impl Castable for __m256

Available on x86 only.
Source§

impl Castable for __m256d

Available on x86 only.
Source§

impl Castable for __m256i

Available on x86 only.
Source§

impl Castable for PhantomPinned

Source§

impl<T, const N: usize> Castable for [T; N]
where T: Castable,

Source§

impl<T: Castable> Castable for PhantomData<T>

Source§

impl<T: Castable> Castable for ManuallyDrop<T>

Source§

impl<T: Castable> Castable for Wrapping<T>

Implementors§