pub struct Pow2Usize(/* private fields */);Expand description
An integer that is known to be a power of two.
The integer is equal to 2^n for some n ≥ 0.
Implementations§
Source§impl Pow2Usize
impl Pow2Usize
Sourcepub const fn new_unchecked(n: usize) -> Self
pub const fn new_unchecked(n: usize) -> Self
Sourcepub const fn log2(self) -> u32
pub const fn log2(self) -> u32
Return the binary logarithm of the value.
The integer is equal to 2^n for some n ≥ 0. Return n.
Sourcepub const fn mul2(self) -> Self
pub const fn mul2(self) -> Self
Multiply the value by two. Return the next power of two.
The integer is equal to 2^n for some n ≥ 0. Return 2^(n + 1).
Sourcepub const fn checked_div2(self) -> Option<Self>
pub const fn checked_div2(self) -> Option<Self>
Divide the value by two. Return the previous power of two, if it exists.
- If the integer is equal to 2^(n + 1) for some n ≥ 0, then return
Some(2^n). - If the integer is equal to 2^0, then return
None.
Trait Implementations§
Source§impl From<NonZeroPow2Usize> for Pow2Usize
impl From<NonZeroPow2Usize> for Pow2Usize
Source§fn from(value: NonZeroPow2Usize) -> Self
fn from(value: NonZeroPow2Usize) -> Self
Converts to this type from the input type.
Source§impl Ord for Pow2Usize
impl Ord for Pow2Usize
Source§impl PartialOrd for Pow2Usize
impl PartialOrd for Pow2Usize
impl Copy for Pow2Usize
impl Eq for Pow2Usize
impl StructuralPartialEq for Pow2Usize
Auto Trait Implementations§
impl Freeze for Pow2Usize
impl RefUnwindSafe for Pow2Usize
impl Send for Pow2Usize
impl Sync for Pow2Usize
impl Unpin for Pow2Usize
impl UnwindSafe for Pow2Usize
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> 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>
Converts
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>
Converts
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