Trait OptionUtils

Source
pub trait OptionUtils<T> {
    // Required methods
    fn or_default_with(self, fallback: T) -> T;
    fn if_some<F: FnOnce(&T)>(self, f: F) -> Option<T>;
}
Expand description

Extension methods for Option<T>.

Required Methods§

Source

fn or_default_with(self, fallback: T) -> T

Returns the value inside Some, or the fallback if None.

Source

fn if_some<F: FnOnce(&T)>(self, f: F) -> Option<T>

Executes a closure if the Option is Some.

Returns the same Option back.

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<T> OptionUtils<T> for Option<T>

Source§

fn or_default_with(self, fallback: T) -> T

Source§

fn if_some<F: FnOnce(&T)>(self, f: F) -> Option<T>

Implementors§