Trait controlled_option::Niche [−][src]
pub trait Niche: Sized {
type Output;
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.
Associated Types
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
Returns the niche value for this type that should be used to represent None for a
ControlledOption.
Returns whether value is the niche value for this type.
Transforms a non-niche value of this type into its Output type. When Output is Self,
this will be the identity function.