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: Zero,
impl<T> NonZero<T>where
T: Zero,
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 replace(&mut self, new_value: T) -> Option<T>
pub fn replace(&mut self, new_value: T) -> Option<T>
Tries replacing the nonzero value with a new one. If the new value is nonzero this returns the old value, otherwise this returns None.
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
Sourcepub const unsafe fn get_mut(&mut self) -> &mut T
👎Deprecated since 0.3.14: use swap instead
pub const unsafe fn get_mut(&mut self) -> &mut T
swap insteadA mutable reference to the nonzero value
§Safety
The caller must guarantee that the value is nonzero when the mutable reference is dropped
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Destructures the NonZero, returning the contained value.
You should probably use get unless you are trying to avoid cloning.