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§
Sourcetype Output
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§
Sourcefn none() -> Self::Output
fn none() -> Self::Output
Returns the niche value for this type that should be used to represent None for a
ControlledOption.
Sourcefn is_none(value: &Self::Output) -> bool
fn is_none(value: &Self::Output) -> bool
Returns whether value is the niche value for this type.
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.