Context

Trait Context 

Source
pub trait Context<Ok, Kind> {
    // Required method
    fn context<Func, Str>(self, context: Func) -> Result<Ok, Error<Kind>>
       where Self: Sized,
             Func: FnOnce() -> Str,
             Str: Into<String>;
}
Expand description

Extension trait for Result and Option to add context to errors. It is similar to anyhow’s Context trait, but it doesn’t have a separation between .context() and .with_context() methods, and it has only a single one that always takes a closure.

Required Methods§

Source

fn context<Func, Str>(self, context: Func) -> Result<Ok, Error<Kind>>
where Self: Sized, Func: FnOnce() -> Str, Str: Into<String>,

Add a message to the error if it is Err or None. This will produce a Result with the uncategorized error.

When invoked on a Result type, the error of the result will be the source of the new error.

Implementations on Foreign Types§

Source§

impl<Ok, Err, Kind> Context<Ok, Kind> for Result<Ok, Err>
where Err: Error + Send + Sync + 'static,

Source§

fn context<Func, Str>(self, context: Func) -> Result<Ok, Error<Kind>>
where Self: Sized, Func: FnOnce() -> Str, Str: Into<String>,

Source§

impl<Ok, Kind> Context<Ok, Kind> for Option<Ok>

Source§

fn context<Func, Str>(self, context: Func) -> Result<Ok, Error<Kind>>
where Self: Sized, Func: FnOnce() -> Str, Str: Into<String>,

Implementors§