Skip to main content

ResultExt

Trait ResultExt 

Source
pub trait ResultExt<T, E> {
    // Required methods
    fn log_error(self, msg: &str) -> Self;
    fn with_context<F, C>(self, f: F) -> Result<T, ContextError<E, C>>
       where F: FnOnce() -> C,
             E: StdError + 'static,
             C: Display + Debug + Send + Sync + 'static;
}
Expand description

Extension trait for Result to add logging and context

Required Methods§

Source

fn log_error(self, msg: &str) -> Self

Log the error if it is Err, and return self

Source

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

Attach context to the error

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> ResultExt<T, E> for Result<T, E>
where E: StdError + 'static,

Source§

fn log_error(self, msg: &str) -> Self

Source§

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

Implementors§