pub union AlignAs<T: Copy, A: Copy> {
/* private fields */
}Expand description
Wrap an object of type T to give it the alignment requirements of an object of type A.
This has a similar effect to #[repr(align(…))], but is parameterized to support the creation of structures that are generic over alignment.
Example:
extern crate alignas;
use alignas::AlignAs;
use std::{mem, slice};
// put some byte data into the buffer
let mut buffer: AlignAs<_, u64> = AlignAs::new([0u8; 64]);
buffer[3..18].copy_from_slice(b"some input here");
// now do something with it that requires aligned access...
let mut ints = [0u64; 8];
let ptr = &buffer as *const _ as *const u64;
ints.copy_from_slice(unsafe { slice::from_raw_parts(ptr, 8) });Implementations§
Trait Implementations§
Source§impl<T: Ord + Copy, A: Copy> Ord for AlignAs<T, A>
impl<T: Ord + Copy, A: Copy> Ord for AlignAs<T, A>
Source§impl<T: PartialOrd + Copy, A: Copy> PartialOrd for AlignAs<T, A>
impl<T: PartialOrd + Copy, A: Copy> PartialOrd for AlignAs<T, A>
impl<T: Copy + Copy, A: Copy + Copy> Copy for AlignAs<T, A>
impl<T: Eq + Copy, A: Copy> Eq for AlignAs<T, A>
Auto Trait Implementations§
impl<T, A> Freeze for AlignAs<T, A>
impl<T, A> RefUnwindSafe for AlignAs<T, A>where
T: RefUnwindSafe,
A: RefUnwindSafe,
impl<T, A> Send for AlignAs<T, A>
impl<T, A> Sync for AlignAs<T, A>
impl<T, A> Unpin for AlignAs<T, A>
impl<T, A> UnwindSafe for AlignAs<T, A>where
T: UnwindSafe,
A: UnwindSafe,
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