Niche

Trait Niche 

Source
pub trait Niche: Sized {
    type Output;

    // Required methods
    fn none() -> Self::Output;
    fn is_none(value: &Self::Output) -> bool;
    fn into_some(value: Self) -> Self::Output;
    fn from_some(value: Self::Output) -> Self;
}
Expand description

A type should implement Niche if its memory representation has any bit patterns that do not represent valid values. If so, one of those can be used to represent the None case of an option.

Required Associated Types§

Source

type Output

The type that is used to store values of Self inside of a ControlledOption. This might be Self itself, if your niche is a valid instance of the type, but which violates some runtime constraint. But if you cannot easily create your niche as an instance of Self, you can use some other type, you can use some other type instead.

A word of caution: is it this Output type that is stored inside of a ControlledOption. If you want ControlledOption<Self> to have the same memory layout as Self (so that you can use #[repr(transparent)], for instance), then you must ensure that Self and Output have the same layout, as determined by std::alloc::Layout::new, and that every valid bit pattern for Self is be a valid bit pattern for Output that returns true for is_some.

Required Methods§

Source

fn none() -> Self::Output

Returns the niche value for this type that should be used to represent None for a ControlledOption.

Source

fn is_none(value: &Self::Output) -> bool

Returns whether value is the niche value for this type.

Source

fn into_some(value: Self) -> Self::Output

Transforms a non-niche value of this type into its Output type. When Output is Self, this will be the identity function.

Source

fn from_some(value: Self::Output) -> Self

Transforms a non-niche value of this type from its Output type. When Output is Self, this will be the identity function.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Niche for NonZeroI8

Source§

type Output = i8

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroI16

Source§

type Output = i16

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroI32

Source§

type Output = i32

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroI64

Source§

type Output = i64

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroIsize

Source§

type Output = isize

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroU8

Source§

type Output = u8

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroU16

Source§

type Output = u16

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroU32

Source§

type Output = u32

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroU64

Source§

type Output = u64

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl Niche for NonZeroUsize

Source§

type Output = usize

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl<'a, T> Niche for &'a T

Source§

type Output = *const T

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Source§

impl<'a, T> Niche for &'a mut T

Source§

type Output = *mut T

Source§

fn none() -> Self::Output

Source§

fn is_none(value: &Self::Output) -> bool

Source§

fn into_some(value: Self) -> Self::Output

Source§

fn from_some(value: Self::Output) -> Self

Implementors§