Skip to main content

OptionExt

Trait OptionExt 

Source
pub trait OptionExt<T> {
    // Required methods
    fn try_map<U, E>(
        self,
        f: impl FnOnce(T) -> Result<U, E>,
    ) -> Result<Option<U>, E>;
    fn is_some_and(self, pred: impl FnOnce(&T) -> bool) -> bool;
    fn is_none_or(self, pred: impl FnOnce(&T) -> bool) -> bool;
    fn and_also(self, other: Option<T>) -> Option<(T, T)>;
    fn inspect_opt(self, f: impl FnOnce(&T)) -> Self;
    fn to_vec(self) -> Vec<T>;
    fn expect_msg(self, msg: &str) -> T;
}
Expand description

Extension methods for Option<T>.

Provides a fluent API for common option operations used throughout the OxiLean elaborator.

Required Methods§

Source

fn try_map<U, E>( self, f: impl FnOnce(T) -> Result<U, E>, ) -> Result<Option<U>, E>

Map with a fallible function.

Source

fn is_some_and(self, pred: impl FnOnce(&T) -> bool) -> bool

Return true if Some and the predicate holds.

Source

fn is_none_or(self, pred: impl FnOnce(&T) -> bool) -> bool

Return true if None or the predicate holds.

Source

fn and_also(self, other: Option<T>) -> Option<(T, T)>

Chain two options: if self is Some, also check other.

Source

fn inspect_opt(self, f: impl FnOnce(&T)) -> Self

Inspect the inner value without consuming.

Source

fn to_vec(self) -> Vec<T>

Convert to a vector (0 or 1 elements).

Source

fn expect_msg(self, msg: &str) -> T

Unwrap with a custom panic message.

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

Source§

fn try_map<U, E>( self, f: impl FnOnce(T) -> Result<U, E>, ) -> Result<Option<U>, E>

Source§

fn is_some_and(self, pred: impl FnOnce(&T) -> bool) -> bool

Source§

fn is_none_or(self, pred: impl FnOnce(&T) -> bool) -> bool

Source§

fn and_also(self, other: Option<T>) -> Option<(T, T)>

Source§

fn inspect_opt(self, f: impl FnOnce(&T)) -> Self

Source§

fn to_vec(self) -> Vec<T>

Source§

fn expect_msg(self, msg: &str) -> T

Implementors§