Trait Unaligned

unsafe trait Unaligned

Types with no alignment requirement.

If T: Unaligned, then align_of::<T>() == 1.

Implementation

Do not implement this trait yourself! Instead, use #[derive(Unaligned)]; e.g.:

# use zerocopy_derive::Unaligned;
#[derive(Unaligned)]
#[repr(C)]
struct MyStruct {
# /*
    ...
# */
}

#[derive(Unaligned)]
#[repr(u8)]
enum MyEnum {
#   Variant0,
# /*
    ...
# */
}

#[derive(Unaligned)]
#[repr(packed)]
union MyUnion {
#   variant: u8,
# /*
    ...
# */
}

This derive performs a sophisticated, compile-time safety analysis to determine whether a type is Unaligned.

Safety

This section describes what is required in order for T: Unaligned, and what unsafe code may assume of such types. If you don't plan on implementing Unaligned manually, and you don't plan on writing unsafe code that operates on Unaligned types, then you don't need to read this section.

If T: Unaligned, then unsafe code may assume that it is sound to produce a reference to T at any memory location regardless of alignment. If a type is marked as Unaligned which violates this contract, it may cause undefined behavior.

#[derive(Unaligned)] only permits types which satisfy these requirements.

Implementors