pub struct NonZero<T> { /* private fields */ }Expand description
An integer that is known to not equal zero.
Implementations§
Source§impl<T> NonZero<T>where
T: Integer,
impl<T> NonZero<T>where
T: Integer,
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: impl Fn(T) -> T) -> Self
pub unsafe fn map_unchecked(self, f: impl 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
Source§impl<T> NonZero<T>
impl<T> NonZero<T>
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
Sourcepub fn without_trailing_zeros(self) -> Self
pub fn without_trailing_zeros(self) -> Self
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> Ord for NonZero<T>
impl<T: Ord> 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: PartialOrd> PartialOrd for NonZero<T>
impl<T: PartialOrd> PartialOrd for NonZero<T>
impl<T: Copy> Copy for NonZero<T>
impl<T: Eq> Eq for NonZero<T>
impl<T> StructuralPartialEq for NonZero<T>
Auto Trait Implementations§
impl<T> Freeze for NonZero<T>where
T: Freeze,
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