Trait ResultExt

Source
pub trait ResultExt<T, E> {
    // Required methods
    fn context<C>(self, context: C) -> Result<T, ContextError<E, C>>;
    fn with_context<C, F>(self, f: F) -> Result<T, ContextError<E, C>>
       where F: FnOnce() -> C;
}
Expand description

Extension trait for Result types to add context to errors

Required Methods§

Source

fn context<C>(self, context: C) -> Result<T, ContextError<E, C>>

Adds context to the error variant of the Result

Source

fn with_context<C, F>(self, f: F) -> Result<T, ContextError<E, C>>
where F: FnOnce() -> C,

Adds context to the error variant using a closure that is only called on error

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, E> ResultExt<T, E> for Result<T, E>

Source§

fn context<C>(self, context: C) -> Result<T, ContextError<E, C>>

Source§

fn with_context<C, F>(self, f: F) -> Result<T, ContextError<E, C>>
where F: FnOnce() -> C,

Implementors§