pub unsafe trait Aligned {
const ALIGNMENT: usize;
}Expand description
Types (may not be pointers) that can be used in EnumPtr.
Safety
Tmust be exactly one-pointer wide.T’s pointee must be aligned byALIGNMENT(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>>
impl<T> Aligned for Option<Rc<T>>
It makes assumption on the layout of Rc. Use it with caution.
source§impl<T> Aligned for Option<Arc<T>>
impl<T> Aligned for Option<Arc<T>>
It makes assumption on the layout of Arc. Use it with caution.