pub struct Align<const N: usize>(/* private fields */)
where
Self: Alignment;Expand description
A zero-sized type that may be embedded in other types to guarantee an
alignment of N bytes. Alignment is provided as a const generic parameter,
allowing for better configurability.
assert_eq!(align_of::<Align<1>>(), 1);
assert_eq!(align_of::<Align<2>>(), 2);
assert_eq!(align_of::<Align<4>>(), 4);
// etc..This can be embedded in types to guarantee the alignment. Ordering will generally matter, as the alignment type must be the first field in the struct.
struct AlignedArray<T, const N: usize>(Align<16>, [T; N]);
let aligned = AlignedArray::<f32, 4>(Align::new(), [0.0, 0.0, 0.0, 0.0]);
assert_eq!(align_of::<Align<1>>(), 1);
assert_eq!(align_of::<Align<2>>(), 2);
assert_eq!(align_of::<Align<4>>(), 4);Implementations§
Trait Implementations§
source§impl<const N: usize> Ord for Align<N>where
Self: Alignment,
impl<const N: usize> Ord for Align<N>where
Self: Alignment,
source§impl<const N: usize> PartialOrd for Align<N>where
Self: Alignment,
impl<const N: usize> PartialOrd for Align<N>where
Self: Alignment,
impl Alignment for Align<1>
impl Alignment for Align<1024>
impl Alignment for Align<128>
impl Alignment for Align<16>
impl Alignment for Align<2>
impl Alignment for Align<2048>
impl Alignment for Align<256>
impl Alignment for Align<32>
impl Alignment for Align<4>
impl Alignment for Align<4096>
impl Alignment for Align<512>
impl Alignment for Align<64>
impl Alignment for Align<8>
impl<const N: usize> Copy for Align<N>where
Self: Alignment,
impl<const N: usize> Eq for Align<N>where
Self: Alignment,
impl<const N: usize> StructuralPartialEq for Align<N>where
Self: Alignment,
Auto Trait Implementations§
impl<const N: usize> !Freeze for Align<N>
impl<const N: usize> !RefUnwindSafe for Align<N>
impl<const N: usize> Send for Align<N>
impl<const N: usize> Sync for Align<N>
impl<const N: usize> Unpin for Align<N>
impl<const N: usize> !UnwindSafe for Align<N>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)