Trait Pod

Source
pub unsafe trait Pod: 'static { }
Expand description

Types whose values can be safely transmuted between byte arrays of the same size.

§Safety

It must be safe to transmute between any byte array (with length equal to the size of the type) and Self.

This is true for these primitive types: i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64. The raw pointer types are not pod under strict provenance rules but can be through the ‘int2ptr’ feature. Primitives such as str and bool are not pod because not every valid byte pattern is a valid instance of these types. References or types with lifetimes are never pod.

Arrays and slices of pod types are also pod themselves.

Note that it is legal for pod types to be a ZST.

When Pod is implemented for a user defined type it must meet the following requirements:

  • Must be annotated with #[repr(C)] or #[repr(transparent)].
  • Must have every field’s type implement Pod itself.
  • Must not have any padding between its fields, define dummy fields to cover the padding.

§Derive macro

To help with safely implementing this trait for user defined types, a derive macro is provided to implement the Pod trait if the requirements are satisfied.

Implementations on Foreign Types§

Source§

impl Pod for f32

Source§

impl Pod for f64

Source§

impl Pod for i8

Source§

impl Pod for i16

Source§

impl Pod for i32

Source§

impl Pod for i64

Source§

impl Pod for i128

Source§

impl Pod for isize

Source§

impl Pod for u8

Source§

impl Pod for u16

Source§

impl Pod for u32

Source§

impl Pod for u64

Source§

impl Pod for u128

Source§

impl Pod for ()

Source§

impl Pod for usize

Source§

impl<T: 'static> Pod for PhantomData<T>

Source§

impl<T: Pod> Pod for [T]

Source§

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

Implementors§