pub trait OptionExtensions<T>: Sized {
// Required methods
fn convert<U>(self, converter: impl FnOnce(T) -> U) -> Option<U>;
fn convert_optional<U>(
self,
converter: impl FnOnce(T) -> Option<U>,
) -> Option<U>;
fn convert_or<U>(
self,
converter: impl FnOnce(T) -> U,
fallback_converter: impl FnOnce() -> U,
) -> U;
fn if_has_value(self, action: impl FnOnce(T)) -> OptionElse;
fn value_or(self, value_selector: impl FnOnce() -> T) -> T;
fn value_or_default(self) -> T
where T: Default;
fn value_or_throw<E>(
self,
exception_generator: impl FnOnce() -> E,
) -> Result<T, E>;
}Expand description
The extensions of an option (OptionExtensions on Optional<T>).
Required Methods§
Sourcefn convert<U>(self, converter: impl FnOnce(T) -> U) -> Option<U>
fn convert<U>(self, converter: impl FnOnce(T) -> U) -> Option<U>
The value converted by converter, or none (Convert(Func<TSource, TDestination>)).
Sourcefn convert_optional<U>(
self,
converter: impl FnOnce(T) -> Option<U>,
) -> Option<U>
fn convert_optional<U>( self, converter: impl FnOnce(T) -> Option<U>, ) -> Option<U>
The option that converter makes of the value, or none
(Convert(Func<TSource, Optional<TDestination>>)).
Sourcefn convert_or<U>(
self,
converter: impl FnOnce(T) -> U,
fallback_converter: impl FnOnce() -> U,
) -> U
fn convert_or<U>( self, converter: impl FnOnce(T) -> U, fallback_converter: impl FnOnce() -> U, ) -> U
The value converted by converter, or what fallback_converter makes when there is none
(ConvertOr).
Sourcefn if_has_value(self, action: impl FnOnce(T)) -> OptionElse
fn if_has_value(self, action: impl FnOnce(T)) -> OptionElse
Runs action with the value; the result runs its else_ action when there is none
(IfHasValue(Action<T>)).
Sourcefn value_or(self, value_selector: impl FnOnce() -> T) -> T
fn value_or(self, value_selector: impl FnOnce() -> T) -> T
The value, or what value_selector makes when there is none (ValueOr(Func<T>)).
Sourcefn value_or_default(self) -> Twhere
T: Default,
fn value_or_default(self) -> Twhere
T: Default,
The value, or the default value of T (ValueOrDefault).
Sourcefn value_or_throw<E>(
self,
exception_generator: impl FnOnce() -> E,
) -> Result<T, E>
fn value_or_throw<E>( self, exception_generator: impl FnOnce() -> E, ) -> Result<T, E>
The value, or the error that exception_generator makes when there is none
(ValueOrThrow).
Deviation (DEVIATIONS.md, DynamicData): upstream throws the exception; the port returns it
as the Err of the result.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".