Skip to main content

Unaligned

Trait Unaligned 

Source
pub unsafe trait Unaligned { }
Expand description

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.:

#[derive(Unaligned)]
#[repr(C)]
struct MyStruct {
    ...
}

#[derive(Unaligned)]
#[repr(u8)]
enum MyEnum {
    ...
}

#[derive(Unaligned)]
#[repr(packed)]
union MyUnion {
    ...
}

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Unaligned for ()

Source§

impl Unaligned for AtomicBool

Available on rust=1.60.0 and target_has_atomic=8 only.
Source§

impl Unaligned for AtomicI8

Available on rust=1.60.0 and target_has_atomic=8 only.
Source§

impl Unaligned for AtomicU8

Available on rust=1.60.0 and target_has_atomic=8 only.
Source§

impl Unaligned for NonZeroI8

Source§

impl Unaligned for NonZeroU8

Source§

impl Unaligned for Option<NonZeroI8>

Source§

impl Unaligned for Option<NonZeroU8>

Source§

impl Unaligned for bool

Source§

impl Unaligned for i8

Source§

impl Unaligned for str

Source§

impl Unaligned for u8

Source§

impl<T: ?Sized + Unaligned> Unaligned for Cell<T>

Source§

impl<T: ?Sized + Unaligned> Unaligned for ManuallyDrop<T>

Source§

impl<T: ?Sized + Unaligned> Unaligned for UnsafeCell<T>

Source§

impl<T: ?Sized> Unaligned for PhantomData<T>

Source§

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

Source§

impl<T: Unaligned> Unaligned for CoreMaybeUninit<T>

Source§

impl<T: Unaligned> Unaligned for Wrapping<T>

Source§

impl<T: Unaligned> Unaligned for [T]

Implementors§

Source§

impl<O> Unaligned for F32<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for F64<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for I16<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for I32<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for I64<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for I128<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for Isize<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for U16<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for U32<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for U64<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for U128<O>

Available on crate features derive only.
Source§

impl<O> Unaligned for Usize<O>

Available on crate features derive only.
Source§

impl<T: ?Sized + Unaligned> Unaligned for ReadOnly<T>

Source§

impl<T> Unaligned for Unalign<T>

Available on crate features derive only.