IsNone

Trait IsNone 

Source
pub trait IsNone: Clone
where 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 types T, Inner is T itself. For Option<T>, Inner is T. This allows Option<T::Inner> to be the same type for both T and Option<T>.

  • Cast<U>: A type that represents the result of casting to another IsNone type. For regular types, Cast<U> is typically U. For Option<T>, Cast<U> is Option<U>. This allows operations like Option<T>::cast<f64>() to result in Option<f64>, while T::cast<f64>() results in f64.

§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 an Option<Inner>.
  • as_opt: Get a reference as an Option<&Inner>.
  • from_inner: Create an instance from an Inner value.
  • inner_cast: Cast between different IsNone types.

§Provided Methods

The trait also provides default implementations for:

  • from_opt: Create an instance from an Option<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§

Source

type Inner: IsNone<Inner = Self::Inner>

Source

type Cast<U: IsNone<Inner = U>>: IsNone<Inner = U>

Required Methods§

Source

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.

Source

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.

Source

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), where inner is the wrapped value.
§Returns

An Option<Self::Inner> representing the current value.

Source

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), where inner is a reference to the wrapped value.
§Returns

An Option<&Self::Inner> representing a reference to the current value.

Source

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.

Source

fn inner_cast<U: IsNone<Inner = U>>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

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 implement IsNone and have Inner = U.
§Arguments
  • inner: The value of type U to be cast.
§Returns

Returns Self::Cast<U>, which is the result of casting Self to a type that can hold U.

Provided Methods§

Source

fn from_opt(opt: Option<Self::Inner>) -> Self

Creates a new instance of Self from an Option<Self::Inner>.

Source

fn unwrap(self) -> Self::Inner

Source

fn not_none(&self) -> bool

Source

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

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 target IsNone type.
§Arguments
  • self: The IsNone value to map over.
  • f: A function that takes Self::Inner and returns U::Inner.
§Returns

Returns a new IsNone value of type U, which is either:

  • The result of applying f to the inner value, wrapped in U, if self is not none.
  • The none value of U, if self is none.
Source

fn vabs(self) -> Self
where Self::Inner: Number,

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 the Number trait, which provides the abs() method.
§Returns

Returns a new Self instance containing:

  • The absolute value of the inner value, if self is not none.
  • The none value of Self, if self is none.
Source

fn sort_cmp(&self, other: &Self) -> Ordering
where 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 first IsNone value to compare.
  • other - The second IsNone value to compare.
§Returns

Returns an Ordering that can be used for sorting:

  • Ordering::Less if self is less than other.
  • Ordering::Equal if self is equal to other.
  • Ordering::Greater if self is greater than other or if self is None.
§Type Constraints
  • Self::Inner: Must implement the PartialOrd trait.
§Notes
  • If both values are Some, their inner values are compared using partial_cmp.
  • If the inner values can’t be compared (e.g., NaN for floats), None is considered greater.
  • If both values are None, they are considered equal.
  • A None value is always considered greater than any Some value.
Source

fn sort_cmp_rev(&self, other: &Self) -> Ordering
where 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 first IsNone value to compare.
  • other - The second IsNone value to compare.
§Returns

Returns an Ordering that can be used for reverse sorting:

  • Ordering::Less if self is greater than other.
  • Ordering::Equal if self is equal to other.
  • Ordering::Greater if self is less than other or if self is None.
§Type Constraints
  • Self::Inner: Must implement the PartialOrd trait.
§Notes
  • If both values are Some, their inner values are compared using partial_cmp and then reversed.
  • If the inner values can’t be compared (e.g., NaN for floats), None is considered greater.
  • If both values are None, they are considered equal.
  • A None value is always considered greater than any Some value.

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 IsNone for bool

Source§

fn sort_cmp(&self, other: &Self) -> Ordering
where Self: PartialOrd,

only for sorting(from smallest to largest)

Source§

type Inner = bool

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for f32

Source§

type Inner = f32

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for f64

Source§

type Inner = f64

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for i32

Source§

fn sort_cmp(&self, other: &Self) -> Ordering
where Self: PartialOrd,

only for sorting(from smallest to largest)

Source§

type Inner = i32

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for i64

Source§

fn sort_cmp(&self, other: &Self) -> Ordering
where Self: PartialOrd,

only for sorting(from smallest to largest)

Source§

type Inner = i64

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for isize

Source§

fn sort_cmp(&self, other: &Self) -> Ordering
where Self: PartialOrd,

only for sorting(from smallest to largest)

Source§

type Inner = isize

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for u8

Source§

fn sort_cmp(&self, other: &Self) -> Ordering
where Self: PartialOrd,

only for sorting(from smallest to largest)

Source§

type Inner = u8

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for u64

Source§

fn sort_cmp(&self, other: &Self) -> Ordering
where Self: PartialOrd,

only for sorting(from smallest to largest)

Source§

type Inner = u64

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for usize

Source§

fn sort_cmp(&self, other: &Self) -> Ordering
where Self: PartialOrd,

only for sorting(from smallest to largest)

Source§

type Inner = usize

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl IsNone for String

Source§

type Inner = String

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl<'a> IsNone for &'a str

Source§

type Inner = &'a str

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl<T: Clone> IsNone for Vec<T>

Source§

type Inner = Vec<T>

Source§

type Cast<U: IsNone<Inner = U>> = U

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn unwrap(self) -> Self::Inner

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Source§

impl<T: IsNone<Inner = T>> IsNone for Option<T>

Source§

type Inner = T

Source§

type Cast<U: IsNone<Inner = U> + Clone> = Option<U>

Source§

fn is_none(&self) -> bool

Source§

fn none() -> Self

Source§

fn to_opt(self) -> Option<Self::Inner>

Source§

fn as_opt(&self) -> Option<&Self::Inner>

Source§

fn from_inner(inner: Self::Inner) -> Self

Source§

fn inner_cast<U: IsNone<Inner = U> + Clone>(inner: U) -> Self::Cast<U>
where Self::Inner: Cast<U::Inner>,

Source§

fn not_none(&self) -> bool

Source§

fn map<F, U: IsNone>(self, f: F) -> U
where F: Fn(Self::Inner) -> U::Inner,

Implementors§

Source§

impl IsNone for Time

Available on crate feature time only.
Source§

type Inner = Time

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

impl IsNone for TimeDelta

Available on crate feature time only.
Source§

type Inner = TimeDelta

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U

Source§

impl<Unit: TimeUnitTrait> IsNone for DateTime<Unit>

Available on crate feature time only.
Source§

type Inner = DateTime<Unit>

Source§

type Cast<U: IsNone<Inner = U> + Clone> = U