Struct beetle_nonzero::NonZero
source · pub struct NonZero<T: PrimInt + Integer> { /* private fields */ }Expand description
An integer that is known to not equal zero.
Implementations§
source§impl<T> NonZero<T>
impl<T> NonZero<T>
sourcepub const unsafe fn new_unchecked(value: T) -> Self
pub const unsafe fn new_unchecked(value: T) -> Self
Returns a new NonZero without checking that the provided value is nonzero.
§Safety
value must be known to be nonzero
sourcepub fn set(&mut self, value: T) -> bool
pub fn set(&mut self, value: T) -> bool
Sets self.value using the provided value.
Only succeeds if the value provided was nonzero.
Returns whether the operation succeeded.
sourcepub unsafe fn set_unchecked(&mut self, value: T)
pub unsafe fn set_unchecked(&mut self, value: T)
Sets the internal value of the nonzero integer. If the value equals zero, this panics.
§Safety
value must be known to be nonzero
sourcepub fn map(self, f: impl Fn(T) -> T) -> Option<Self>
pub fn map(self, f: impl Fn(T) -> T) -> Option<Self>
Applies a function to the inner value and returns a NonZero if the result was nonzero.
sourcepub unsafe fn map_unchecked(self, f: fn(_: T) -> T) -> Self
pub unsafe fn map_unchecked(self, f: fn(_: T) -> T) -> Self
Applies a function to the inner value and returns a NonZero if the result was nonzero.
§Safety
f must return a nonzero integer
sourcepub fn trailing_zeros(self) -> u32
pub fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation of the nonzero integer
Trait Implementations§
source§impl From<NonZero<u128>> for NonZero<u128>
impl From<NonZero<u128>> for NonZero<u128>
source§fn from(value: NonZeroU128) -> Self
fn from(value: NonZeroU128) -> Self
Converts to this type from the input type.
source§impl From<NonZero<u16>> for NonZero<u16>
impl From<NonZero<u16>> for NonZero<u16>
source§fn from(value: NonZeroU16) -> Self
fn from(value: NonZeroU16) -> Self
Converts to this type from the input type.
source§impl From<NonZero<u32>> for NonZero<u32>
impl From<NonZero<u32>> for NonZero<u32>
source§fn from(value: NonZeroU32) -> Self
fn from(value: NonZeroU32) -> Self
Converts to this type from the input type.
source§impl From<NonZero<u64>> for NonZero<u64>
impl From<NonZero<u64>> for NonZero<u64>
source§fn from(value: NonZeroU64) -> Self
fn from(value: NonZeroU64) -> Self
Converts to this type from the input type.
source§impl From<NonZero<usize>> for NonZero<usize>
impl From<NonZero<usize>> for NonZero<usize>
source§fn from(value: NonZeroUsize) -> Self
fn from(value: NonZeroUsize) -> Self
Converts to this type from the input type.
source§impl<T: Ord + PrimInt + Integer> Ord for NonZero<T>
impl<T: Ord + PrimInt + Integer> Ord for NonZero<T>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<T: PartialEq + PrimInt + Integer> PartialEq for NonZero<T>
impl<T: PartialEq + PrimInt + Integer> PartialEq for NonZero<T>
source§impl<T: PartialOrd + PrimInt + Integer> PartialOrd for NonZero<T>
impl<T: PartialOrd + PrimInt + Integer> PartialOrd for NonZero<T>
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<T: Copy + PrimInt + Integer> Copy for NonZero<T>
impl<T: Eq + PrimInt + Integer> Eq for NonZero<T>
impl<T: PrimInt + Integer> StructuralPartialEq for NonZero<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for NonZero<T>where
T: RefUnwindSafe,
impl<T> Send for NonZero<T>where
T: Send,
impl<T> Sync for NonZero<T>where
T: Sync,
impl<T> Unpin for NonZero<T>where
T: Unpin,
impl<T> UnwindSafe for NonZero<T>where
T: 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