Derive Macro bytemuck::TransparentWrapper

source ·
    // Attributes available to this derive:
Expand description

Derive the TransparentWrapper trait for a struct

The macro ensures that the struct follows all the the safety requirements for the TransparentWrapper trait.

The following constraints need to be satisfied for the macro to succeed

  • The struct must be #[repr(transparent)]
  • The struct must contain the Wrapped type

If the struct only contains a single field, the Wrapped type will automatically be determined if there is more then one field in the struct, you need to specify the Wrapped type using #[transparent(T)]


#[derive(Copy, Clone, TransparentWrapper)]
struct Test<T> {
  inner: u16,
  extra: PhantomData<T>,