Trait enum_ptr::Aligned

source ·
pub unsafe trait Aligned {
    const ALIGNMENT: usize;
}
Expand description

Types (may not be pointers) that can be used in EnumPtr.

Safety

  • T must be exactly one-pointer wide.
  • T’s pointee must be aligned by ALIGNMENT (T’s low bits are zeros).

For example, raw pointers are not guaranteed to be aligned, so implementing this trait for them is unsound.

Examples

use enum_ptr::{Aligned, Compact, EnumPtr};

// It's your responsibility to ensure `MyPtr` is always aligned.
struct MyPtr<T>(*const T);

unsafe impl<T> Aligned for MyPtr<T> {
    const ALIGNMENT: usize = std::mem::align_of::<T>();
}

#[derive(EnumPtr)]
#[repr(C, usize)]
enum Foo {
    A(MyPtr<i64>),
    B(MyPtr<u64>),
}

Required Associated Constants§

Implementations on Foreign Types§

source§

impl<T> Aligned for Option<Rc<T>>

It makes assumption on the layout of Rc. Use it with caution.

source§

impl<T> Aligned for Arc<T>

It makes assumption on the layout of Arc. Use it with caution.

source§

impl<T> Aligned for &mut T

source§

impl<T> Aligned for Option<&T>

source§

impl<T> Aligned for Option<Arc<T>>

It makes assumption on the layout of Arc. Use it with caution.

source§

impl<T> Aligned for Box<T>

source§

impl<T> Aligned for Option<Box<T>>

source§

impl<T> Aligned for Option<&mut T>

source§

impl<T> Aligned for Rc<T>

It makes assumption on the layout of Rc. Use it with caution.

source§

impl<T> Aligned for &T

Implementors§

source§

impl Aligned for Unit

source§

const ALIGNMENT: usize = 4_294_967_295usize

source§

impl<const N: isize> Aligned for ShiftIsize<N>

source§

impl<const N: usize> Aligned for ShiftUsize<N>