Trait nonzero_ext::NonZeroAble
source · pub trait NonZeroAble {
type NonZero: NonZero;
fn as_nonzero(self) -> Option<Self::NonZero>;
unsafe fn as_nonzero_unchecked(self) -> Self::NonZero;
}
Expand description
A trait identifying integral types that have a non-zeroable equivalent.
Required Associated Types§
Required Methods§
sourcefn as_nonzero(self) -> Option<Self::NonZero>
fn as_nonzero(self) -> Option<Self::NonZero>
Converts the integer to its non-zero equivalent.
Examples
Trying to convert zero
let n: u16 = 0;
assert_eq!(n.as_nonzero(), None);
Converting a non-zero value
let n: usize = 20;
let non0n: NonZeroUsize = n.as_nonzero().expect("should result in a converted value");
assert_eq!(non0n.get(), 20);
sourceunsafe fn as_nonzero_unchecked(self) -> Self::NonZero
unsafe fn as_nonzero_unchecked(self) -> Self::NonZero
Converts the integer to its non-zero equivalent without checking for zeroness.
This corresponds to the new_unchecked
function on the
corresponding NonZero type.