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 PartialEq for Alignment
impl PartialEq for Alignment
source§impl PartialOrd for Alignment
impl PartialOrd for Alignment
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl 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> 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