Skip to main content

HasNonZero

Trait HasNonZero 

Source
pub trait HasNonZero: Sized {
    type NonZero: Copy;

    // Required methods
    fn into_nonzero(self) -> Option<Self::NonZero>;
    fn nonzero_get(nz: Self::NonZero) -> Self;
}
Expand description

Bridge to core::num::NonZero — “the non-zero form of Self”.

This does not duplicate core::num::NonZero: for the integer primitives NonZero is core::num::NonZero<Self>, with its real niche. (core::num::NonZero<T> is sealed to primitives, so a future bignum backend supplies its own non-zero type as the associated type instead.)

The value is recovered through the crate-owned const accessor nonzero_get rather than an Into<Self> bound: From<NonZero<T>> for T is not const, so such a bound would poison every generic const consumer.

Required Associated Types§

Source

type NonZero: Copy

The non-zero form of Self (core::num::NonZero<Self> for primitives).

Required Methods§

Source

fn into_nonzero(self) -> Option<Self::NonZero>

Some iff self != 0.

Source

fn nonzero_get(nz: Self::NonZero) -> Self

Recover the underlying value from its non-zero form.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl HasNonZero for u8

Source§

impl HasNonZero for u16

Source§

impl HasNonZero for u32

Source§

impl HasNonZero for u64

Source§

impl HasNonZero for u128

Source§

impl HasNonZero for usize

Implementors§