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

Implementors