pub struct PowerOfTwo(/* private fields */);Implementations§
Source§impl PowerOfTwo
impl PowerOfTwo
Sourcepub const fn new(value: usize) -> Result<Self, NotPowerOfTwo>
pub const fn new(value: usize) -> Result<Self, NotPowerOfTwo>
Create a new PowerOfTwo if the given value is greater a power of two.
Sourcepub const fn next(value: usize) -> Option<Self>
pub const fn next(value: usize) -> Option<Self>
Return the smallest power of two greater than or equal to value. If the next
power of two is greater than usize::MAX, None is returned.
Sourcepub const unsafe fn new_unchecked(value: NonZeroUsize) -> Self
pub const unsafe fn new_unchecked(value: NonZeroUsize) -> Self
Create a new PowerOfTwo without checking whether the value is a power of two.
§Safety
The value must be a power of two.
Sourcepub const fn into_inner(self) -> NonZeroUsize
pub const fn into_inner(self) -> NonZeroUsize
Consume self and return the inner value.
Sourcepub const fn from_align(layout: &Layout) -> Self
pub const fn from_align(layout: &Layout) -> Self
Construct self from the alignment in layout.
Sourcepub const fn alignment_of<T>() -> Self
pub const fn alignment_of<T>() -> Self
Return the alignment of T as a power of two.
Sourcepub const fn arg_mod(self, lhs: usize) -> usize
pub const fn arg_mod(self, lhs: usize) -> usize
Compute the operation lhs % self.
§Note
The argument order of this function is reversed from the typical align_offset
method in the standard library.
Sourcepub const fn arg_align_offset(self, lhs: usize) -> usize
pub const fn arg_align_offset(self, lhs: usize) -> usize
Compute the amount x that would have to be added to lhs so the quantity
lhs + x is a multiple of self.
§Note
The argument order of this function is reversed from the typical align_offset
method in the standard library.
Sourcepub const fn arg_checked_next_multiple_of(self, lhs: usize) -> Option<usize>
pub const fn arg_checked_next_multiple_of(self, lhs: usize) -> Option<usize>
Calculate the smallest value greater than or equal to lhs that is a multiple of
self. Return None if the operation would result in an overflow.
Trait Implementations§
Source§impl Clone for PowerOfTwo
impl Clone for PowerOfTwo
Source§fn clone(&self) -> PowerOfTwo
fn clone(&self) -> PowerOfTwo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PowerOfTwo
impl Debug for PowerOfTwo
Source§impl From<PowerOfTwo> for usize
impl From<PowerOfTwo> for usize
Source§fn from(value: PowerOfTwo) -> Self
fn from(value: PowerOfTwo) -> Self
Source§impl PartialEq for PowerOfTwo
impl PartialEq for PowerOfTwo
impl Copy for PowerOfTwo
impl StructuralPartialEq for PowerOfTwo
Auto Trait Implementations§
impl Freeze for PowerOfTwo
impl RefUnwindSafe for PowerOfTwo
impl Send for PowerOfTwo
impl Sync for PowerOfTwo
impl Unpin for PowerOfTwo
impl UnwindSafe for PowerOfTwo
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more