pub struct NonZero<T> { /* 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
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