Trait nonzero_ext::NonZeroAble

source ·
pub trait NonZeroAble {
    type NonZero: NonZero;

    // Required methods
    fn into_nonzero(self) -> Option<Self::NonZero>;
    unsafe fn into_nonzero_unchecked(self) -> Self::NonZero;

    // Provided methods
    fn as_nonzero(self) -> Option<Self::NonZero>
       where Self: Sized { ... }
    unsafe fn as_nonzero_unchecked(self) -> Self::NonZero
       where Self: Sized { ... }
}
Expand description

A trait identifying integral types that have a non-zeroable equivalent.

Required Associated Types§

source

type NonZero: NonZero

The concrete non-zero type represented by an implementation of this trait. For example, for u8’s implementation, it is NonZeroU8.

Required Methods§

source

fn into_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.into_nonzero(), None);
§Converting a non-zero value
let n: usize = 20;
let non0n: NonZeroUsize = n.into_nonzero().expect("should result in a converted value");
assert_eq!(non0n.get(), 20);
source

unsafe fn into_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.

§Safety

The value must not be zero.

Provided Methods§

source

fn as_nonzero(self) -> Option<Self::NonZero>
where Self: Sized,

👎Deprecated since 0.2.0: Renamed to into_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);
source

unsafe fn as_nonzero_unchecked(self) -> Self::NonZero
where Self: Sized,

👎Deprecated since 0.2.0: Renamed to into_nonzero_unchecked

Converts the integer to its non-zero equivalent without checking for zeroness.

This corresponds to the new_unchecked function on the corresponding NonZero type.

§Safety

The value must not be zero.

Implementations on Foreign Types§

source§

impl NonZeroAble for i8

source§

impl NonZeroAble for i16

source§

impl NonZeroAble for i32

source§

impl NonZeroAble for i64

source§

impl NonZeroAble for i128

source§

impl NonZeroAble for isize

source§

impl NonZeroAble for u8

source§

impl NonZeroAble for u16

source§

impl NonZeroAble for u32

source§

impl NonZeroAble for u64

source§

impl NonZeroAble for u128

source§

impl NonZeroAble for usize

Implementors§