Skip to main content

Context

Trait Context 

Source
pub trait Context<T> {
    // Required methods
    fn context<C: Display + Send + Sync + 'static>(self, ctx: C) -> Result<T>;
    fn with_context<C, F>(self, f: F) -> Result<T>
       where C: Display + Send + Sync + 'static,
             F: FnOnce() -> C;
}
Expand description

Extension trait to add context to errors.

Required Methods§

Source

fn context<C: Display + Send + Sync + 'static>(self, ctx: C) -> Result<T>

Adds context to an error.

§Errors

Returns the original error with the new context attached.

Source

fn with_context<C, F>(self, f: F) -> Result<T>
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Adds lazy context to an error.

§Errors

Returns the original error with the new context attached.

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

Source§

fn context<C: Display + Send + Sync + 'static>(self, ctx: C) -> Result<T>

Source§

fn with_context<C, F>(self, f: F) -> Result<T>
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Source§

impl<T, E> Context<T> for Result<T, E>
where NexError: From<E>,

Source§

fn context<C: Display + Send + Sync + 'static>(self, ctx: C) -> Result<T>

Source§

fn with_context<C, F>(self, f: F) -> Result<T>
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Implementors§