Trait rama::error::ErrorContext

pub trait ErrorContext: SealedErrorContext {
    type Context;

    // Required methods
    fn context<M>(self, context: M) -> Self::Context
       where M: Display + Send + Sync + 'static;
    fn with_context<C, F>(self, context: F) -> Self::Context
       where C: Display + Send + Sync + 'static,
             F: FnOnce() -> C;
}
Expand description

Extends the Result and Option types with methods for adding context to errors.

See the module level documentation for more information.

§Examples

use rama_error::ErrorContext;

let result = "hello".parse::<i32>().context("parse integer");
assert_eq!("parse integer\r\n ↪ invalid digit found in string", result.unwrap_err().to_string());

Required Associated Types§

type Context

The resulting contexct type after adding context to the contained error.

Required Methods§

fn context<M>(self, context: M) -> Self::Context
where M: Display + Send + Sync + 'static,

Add a static context to the contained error.

fn with_context<C, F>(self, context: F) -> Self::Context
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Lazily add a context to the contained error, if it exists.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl<T> ErrorContext for Option<T>

§

type Context = Result<T, OpaqueError>

§

fn context<M>(self, context: M) -> <Option<T> as ErrorContext>::Context
where M: Display + Send + Sync + 'static,

§

fn with_context<C, F>(self, context: F) -> <Option<T> as ErrorContext>::Context
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

§

impl<T, E> ErrorContext for Result<T, E>
where E: Error + Send + Sync + 'static,

§

type Context = Result<T, OpaqueError>

§

fn context<M>(self, context: M) -> <Result<T, E> as ErrorContext>::Context
where M: Display + Send + Sync + 'static,

§

fn with_context<C, F>( self, context: F, ) -> <Result<T, E> as ErrorContext>::Context
where C: Display + Send + Sync + 'static, F: FnOnce() -> C,

Implementors§