Context

Trait Context 

Source
pub trait Context<T> {
    // Required methods
    fn context<C>(self, context: C) -> Result<T>
       where C: Display + Debug + Send + Sync + 'static;
    fn with_context<C, F>(self, f: F) -> Result<T>
       where C: Display + Debug + Send + Sync + 'static,
             F: FnOnce() -> C;
    fn with_field<V>(self, key: &'static str, value: V) -> Result<T>
       where V: Display;
    fn with_field_debug<V>(self, key: &'static str, value: V) -> Result<T>
       where V: Debug;
}
Expand description

Extension trait for adding context and fields to errors.

Required Methods§

Source

fn context<C>(self, context: C) -> Result<T>
where C: Display + Debug + Send + Sync + 'static,

Wrap the error value with additional context.

Source

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

Wrap the error value with additional context that is evaluated lazily.

Source

fn with_field<V>(self, key: &'static str, value: V) -> Result<T>
where V: Display,

Add a named field to the error.

Source

fn with_field_debug<V>(self, key: &'static str, value: V) -> Result<T>
where V: Debug,

Add a named field with debug formatting to the 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> Context<T> for Option<T>

Source§

fn context<C>(self, context: C) -> Result<T>
where C: Display + Debug + Send + Sync + 'static,

Source§

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

Source§

fn with_field<V>(self, key: &'static str, value: V) -> Result<T>
where V: Display,

Source§

fn with_field_debug<V>(self, key: &'static str, value: V) -> Result<T>
where V: Debug,

Source§

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

Source§

fn context<C>(self, context: C) -> Result<T>
where C: Display + Debug + Send + Sync + 'static,

Source§

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

Source§

fn with_field<V>(self, key: &'static str, value: V) -> Result<T>
where V: Display,

Source§

fn with_field_debug<V>(self, key: &'static str, value: V) -> Result<T>
where V: Debug,

Implementors§