Skip to main content

Context

Trait Context 

Source
pub trait Context<T> {
    // Required methods
    fn wrap_err(self, context: impl Display) -> Result<T>;
    fn wrap_err_with<C>(self, context: impl FnOnce() -> C) -> Result<T>
       where C: Display;
}
Expand description

Extension trait that annotates foreign Results with stow-style context.

Implemented for every Result<T, E: Display>; the source error’s Display output becomes the wrapped cause.

Required Methods§

Source

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

Convert the error into Error with context prepended.

§Errors

Returns the source error wrapped in context when self is Err.

Source

fn wrap_err_with<C>(self, context: impl FnOnce() -> C) -> Result<T>
where C: Display,

Lazily evaluated variant of Context::wrap_err: context runs only when self is Err.

§Errors

Returns the source error wrapped in context() when self is Err.

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, E> Context<T> for Result<T, E>
where E: Display,

Source§

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

Source§

fn wrap_err_with<C>(self, context: impl FnOnce() -> C) -> Result<T>
where C: Display,

Implementors§