pub struct Alignment(/* private fields */);
Expand description
Type representing an alignment, which is always a power of two.
It is used to validate that a given value is a valid alignment, and to perform masking and alignment operations.
This is a temporary substitute for the Alignment
nightly type from the standard library,
and to be eventually replaced by it.
§Invariants
An alignment is always a power of two.
Implementations§
Source§impl Alignment
impl Alignment
Sourcepub const fn new_checked(align: usize) -> Option<Self>
pub const fn new_checked(align: usize) -> Option<Self>
Validates that align
is a power of two at runtime, and returns an
Alignment
of the same value.
Returns None
if align
is not a power of two.
§Examples
use kernel::ptr::Alignment;
assert_eq!(Alignment::new_checked(16), Some(Alignment::new::<16>()));
assert_eq!(Alignment::new_checked(15), None);
assert_eq!(Alignment::new_checked(1), Some(Alignment::new::<1>()));
assert_eq!(Alignment::new_checked(0), None);
Sourcepub const fn as_nonzero(self) -> NonZero<usize>
pub const fn as_nonzero(self) -> NonZero<usize>
Trait Implementations§
Source§impl Ord for Alignment
impl Ord for Alignment
Source§impl PartialOrd for Alignment
impl PartialOrd for Alignment
impl Copy for Alignment
impl Eq for Alignment
impl StructuralPartialEq for Alignment
Auto Trait Implementations§
impl Freeze for Alignment
impl RefUnwindSafe for Alignment
impl Send for Alignment
impl Sync for Alignment
impl Unpin for Alignment
impl UnwindSafe for Alignment
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§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot
. Read more