Skip to main content

OptionExt

Trait OptionExt 

Source
pub trait OptionExt<T> {
    // Required methods
    fn context(self, msg: impl Display) -> Result<T>;
    fn with_context<F, M>(self, f: F) -> Result<T>
       where F: FnOnce() -> M,
             M: Display;
}
Expand description

Extension methods on Option<T>.

Required Methods§

Source

fn context(self, msg: impl Display) -> Result<T>

Convert None into an anyhow::Error with the given message.

Source

fn with_context<F, M>(self, f: F) -> Result<T>
where F: FnOnce() -> M, M: Display,

Like OptionExt::context but the message is lazily constructed.

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 context(self, msg: impl Display) -> Result<T>

Source§

fn with_context<F, M>(self, f: F) -> Result<T>
where F: FnOnce() -> M, M: Display,

Implementors§