NoUninit

Derive Macro NoUninit 

Source
#[derive(NoUninit)]
{
    // Attributes available to this derive:
    #[bytemuck]
}
Expand description

Derive the NoUninit trait for a struct or enum

The macro ensures that the type follows all the the safety requirements for the NoUninit trait.

The following constraints need to be satisfied for the macro to succeed (the rest of the constraints are guaranteed by the NoUninit subtrait bounds, i.e. the type must be Sized + Copy + 'static):

If applied to a struct:

  • All fields in the struct must implement NoUninit
  • The struct must be #[repr(C)] or #[repr(transparent)]
  • The struct must not contain any padding bytes
  • The struct must contain no generic parameters

If applied to an enum:

  • The enum must be explicit #[repr(Int)], #[repr(C)], or both
  • If the enum has fields:
    • All fields must implement NoUninit
    • All variants must not contain any padding bytes
    • All variants must be of the the same size
    • There must be no padding bytes between the discriminant and any of the variant fields
  • The enum must contain no generic parameters