pub trait IsNone: Clonewhere
Self: Sized,{
type Inner: IsNone<Inner = Self::Inner>;
type Cast<U: IsNone<Inner = U>>: IsNone<Inner = U>;
Show 13 methods
// Required methods
fn is_none(&self) -> bool;
fn none() -> Self;
fn to_opt(self) -> Option<Self::Inner>;
fn as_opt(&self) -> Option<&Self::Inner>;
fn from_inner(inner: Self::Inner) -> Self;
fn inner_cast<U: IsNone<Inner = U>>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>;
// Provided methods
fn from_opt(opt: Option<Self::Inner>) -> Self { ... }
fn unwrap(self) -> Self::Inner { ... }
fn not_none(&self) -> bool { ... }
fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner { ... }
fn vabs(self) -> Self
where Self::Inner: Number { ... }
fn sort_cmp(&self, other: &Self) -> Ordering
where Self::Inner: PartialOrd { ... }
fn sort_cmp_rev(&self, other: &Self) -> Ordering
where Self::Inner: PartialOrd { ... }
}Expand description
A trait for types that can represent a “none” or null-like state.
This trait is implemented by types that can be in a “none” state,
similar to Rust’s Option type. It provides methods for working
with such types in a generic way.
§Type Parameters
-
Inner: The inner type. For regular typesT,InnerisTitself. ForOption<T>,InnerisT. This allowsOption<T::Inner>to be the same type for bothTandOption<T>. -
Cast<U>: A type that represents the result of casting to anotherIsNonetype. For regular types,Cast<U>is typicallyU. ForOption<T>,Cast<U>isOption<U>. This allows operations likeOption<T>::cast<f64>()to result inOption<f64>, whileT::cast<f64>()results inf64.
§Required Methods
Implementors must define:
is_none: Check if the value is in the “none” state.none: Create a new instance in the “none” state.to_opt: Convert to anOption<Inner>.as_opt: Get a reference as anOption<&Inner>.from_inner: Create an instance from anInnervalue.inner_cast: Cast between differentIsNonetypes.
§Provided Methods
The trait also provides default implementations for:
from_opt: Create an instance from anOption<Inner>.unwrap: Get the inner value, panicking if none.not_none: Check if the value is not in the “none” state.map: Apply a function to the inner value if not none.
Required Associated Types§
type Inner: IsNone<Inner = Self::Inner>
type Cast<U: IsNone<Inner = U>>: IsNone<Inner = U>
Required Methods§
sourcefn is_none(&self) -> bool
fn is_none(&self) -> bool
Checks if the value is in the “none” state.
§Returns
true if the value is in the “none” state, false otherwise.
sourcefn none() -> Self
fn none() -> Self
Creates a new instance of Self in the “none” state.
This method is used to generate a value that represents the absence of a valid value,
similar to None in Rust’s Option type.
§Returns
Returns a new instance of Self that is considered to be in the “none” state.
sourcefn to_opt(self) -> Option<Self::Inner>
fn to_opt(self) -> Option<Self::Inner>
Converts the value to an Option<Self::Inner>.
This method transforms the current value into an Option type, where:
- If the current value is in the “none” state, it returns
None. - Otherwise, it returns
Some(inner), whereinneris the wrapped value.
§Returns
An Option<Self::Inner> representing the current value.
sourcefn as_opt(&self) -> Option<&Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
Converts the value to an Option<&Self::Inner>.
This method returns a reference to the inner value as an Option type, where:
- If the current value is in the “none” state, it returns
None. - Otherwise, it returns
Some(&inner), whereinneris a reference to the wrapped value.
§Returns
An Option<&Self::Inner> representing a reference to the current value.
sourcefn from_inner(inner: Self::Inner) -> Self
fn from_inner(inner: Self::Inner) -> Self
Creates a new instance of Self from the given inner value.
This method converts a value of type Self::Inner into Self.
For example, if Self is f64, Self::Inner is also f64, so this method
would essentially be an identity function. However, if Self is Option<f64>,
Self::Inner would be f64, so this method would wrap the f64 value in Some.
§Arguments
inner- The inner value to be converted.
§Returns
Returns a new instance of Self created from the provided inner value.
sourcefn inner_cast<U: IsNone<Inner = U>>(inner: U) -> Self::Cast<U>
fn inner_cast<U: IsNone<Inner = U>>(inner: U) -> Self::Cast<U>
Casts the inner type of Self to a new type U.
This method allows for casting between different IsNone types, preserving the “none” state
if applicable. It uses the Cast trait to perform the actual type conversion.
§Type Parameters
U: The target type, which must implementIsNoneand haveInner = U.
§Arguments
inner: The value of typeUto be cast.
§Returns
Returns Self::Cast<U>, which is the result of casting Self to a type that can hold U.
Provided Methods§
sourcefn from_opt(opt: Option<Self::Inner>) -> Self
fn from_opt(opt: Option<Self::Inner>) -> Self
Creates a new instance of Self from an Option<Self::Inner>.
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
sourcefn map<F, U: IsNone>(self, f: F) -> U
fn map<F, U: IsNone>(self, f: F) -> U
Maps a function over the inner value of Self, if it exists.
This method applies a given function to the inner value of Self if it’s not none,
and wraps the result in a new IsNone type U. If Self is none, it returns
the none value of type U.
§Type Parameters
F: The type of the mapping function.U: The targetIsNonetype.
§Arguments
self: TheIsNonevalue to map over.f: A function that takesSelf::Innerand returnsU::Inner.
§Returns
Returns a new IsNone value of type U, which is either:
- The result of applying
fto the inner value, wrapped inU, ifselfis not none. - The none value of
U, ifselfis none.
sourcefn vabs(self) -> Self
fn vabs(self) -> Self
Computes the absolute value of the inner value, if it exists.
This method applies the absolute value function to the inner value of Self if it’s not none.
If Self is none, it returns the none value.
§Type Constraints
Self::Inner: Must implement theNumbertrait, which provides theabs()method.
§Returns
Returns a new Self instance containing:
- The absolute value of the inner value, if
selfis not none. - The none value of
Self, ifselfis none.
sourcefn sort_cmp(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
Compares two values for sorting, treating None as the largest value.
This method is designed for sorting Some values from smallest to largest,
with None values considered larger than any non-None value.
§Arguments
self- The firstIsNonevalue to compare.other- The secondIsNonevalue to compare.
§Returns
Returns an Ordering that can be used for sorting:
Ordering::Lessifselfis less thanother.Ordering::Equalifselfis equal toother.Ordering::Greaterifselfis greater thanotheror ifselfisNone.
§Type Constraints
Self::Inner: Must implement thePartialOrdtrait.
§Notes
- If both values are
Some, their inner values are compared usingpartial_cmp. - If the inner values can’t be compared (e.g., NaN for floats),
Noneis considered greater. - If both values are
None, they are considered equal. - A
Nonevalue is always considered greater than anySomevalue.
sourcefn sort_cmp_rev(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
fn sort_cmp_rev(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
Compares two values for reverse sorting, treating None as the largest value.
This method is designed for sorting Some values from largest to smallest,
with None values considered larger than any non-None value.
§Arguments
self- The firstIsNonevalue to compare.other- The secondIsNonevalue to compare.
§Returns
Returns an Ordering that can be used for reverse sorting:
Ordering::Lessifselfis greater thanother.Ordering::Equalifselfis equal toother.Ordering::Greaterifselfis less thanotheror ifselfisNone.
§Type Constraints
Self::Inner: Must implement thePartialOrdtrait.
§Notes
- If both values are
Some, their inner values are compared usingpartial_cmpand then reversed. - If the inner values can’t be compared (e.g., NaN for floats),
Noneis considered greater. - If both values are
None, they are considered equal. - A
Nonevalue is always considered greater than anySomevalue.
Object Safety§
Implementations on Foreign Types§
source§impl IsNone for bool
impl IsNone for bool
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
only for sorting(from smallest to largest)
type Inner = bool
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for f32
impl IsNone for f32
type Inner = f32
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for f64
impl IsNone for f64
type Inner = f64
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for i32
impl IsNone for i32
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
only for sorting(from smallest to largest)
type Inner = i32
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for i64
impl IsNone for i64
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
only for sorting(from smallest to largest)
type Inner = i64
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for isize
impl IsNone for isize
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
only for sorting(from smallest to largest)
type Inner = isize
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for u8
impl IsNone for u8
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
only for sorting(from smallest to largest)
type Inner = u8
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for u64
impl IsNone for u64
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
only for sorting(from smallest to largest)
type Inner = u64
type Cast<U: IsNone<Inner = U> + Clone> = U
fn is_none(&self) -> bool
fn none() -> Self
fn to_opt(self) -> Option<Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
fn from_inner(inner: Self::Inner) -> Self
fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
fn unwrap(self) -> Self::Inner
fn not_none(&self) -> bool
fn map<F, U: IsNone>(self, f: F) -> U
source§impl IsNone for usize
impl IsNone for usize
source§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self: PartialOrd,
only for sorting(from smallest to largest)