Skip to main content

ErrorContext

Trait ErrorContext 

Source
pub trait ErrorContext<T: Display> {
    // Required method
    fn context(self, msg: T) -> Self;

    // Provided method
    fn with_context<F>(self, f: F) -> Self
       where F: FnOnce() -> T,
             Self: Sized { ... }
}

Required Methods§

Source

fn context(self, msg: T) -> Self

Attach context to an error.

Provided Methods§

Source

fn with_context<F>(self, f: F) -> Self
where F: FnOnce() -> T, Self: Sized,

Attach context lazily, so the message is only built when there is actually an error to attach it to.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, M> ErrorContext<M> for Result<T, DecodeError>
where M: Display,

Source§

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

Only render the error on the Err case

Source§

fn context(self, msg: M) -> Result<T, DecodeError>

Implementors§