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§
Sourcefn try_map<U, E>(
self,
f: impl FnOnce(T) -> Result<U, E>,
) -> Result<Option<U>, E>
fn try_map<U, E>( self, f: impl FnOnce(T) -> Result<U, E>, ) -> Result<Option<U>, E>
Map with a fallible function.
Sourcefn is_some_and(self, pred: impl FnOnce(&T) -> bool) -> bool
fn is_some_and(self, pred: impl FnOnce(&T) -> bool) -> bool
Return true if Some and the predicate holds.
Sourcefn is_none_or(self, pred: impl FnOnce(&T) -> bool) -> bool
fn is_none_or(self, pred: impl FnOnce(&T) -> bool) -> bool
Return true if None or the predicate holds.
Sourcefn and_also(self, other: Option<T>) -> Option<(T, T)>
fn and_also(self, other: Option<T>) -> Option<(T, T)>
Chain two options: if self is Some, also check other.
Sourcefn inspect_opt(self, f: impl FnOnce(&T)) -> Self
fn inspect_opt(self, f: impl FnOnce(&T)) -> Self
Inspect the inner value without consuming.
Sourcefn expect_msg(self, msg: &str) -> T
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.