Trait Context

Source
pub trait Context: Sealed {
    // Required methods
    fn module<D>(self, name: D) -> Self
       where D: Display + Send + Sync + 'static,
             Self: Sized;
    fn with_module<D>(self, f: impl FnOnce() -> D) -> Self
       where D: Display + Send + Sync + 'static;
    fn value<D>(self, name: D) -> Self
       where D: Display + Send + Sync + 'static,
             Self: Sized;
    fn with_value<D>(self, f: impl FnOnce() -> D) -> Self
       where D: Display + Send + Sync + 'static,
             Self: Sized;
}
Expand description

Extension trait for Result.

Adds methods for adding context to an Error.

This trait is sealed and cannot be implemented for any other types.

Required Methods§

Source

fn module<D>(self, name: D) -> Self
where D: Display + Send + Sync + 'static, Self: Sized,

Add the name of this module to the context of the error.

This method adds context to the Error so that it knows in which module the error occurred. It is perfectly fine to never use it, as long as you don’t mind cryptic errors.

Modules should be added in the following order, from the module where the error occured and then its parent module up until the root module.

Source

fn with_module<D>(self, f: impl FnOnce() -> D) -> Self
where D: Display + Send + Sync + 'static,

The same as Context::module but lazily-evaluated.

Source

fn value<D>(self, name: D) -> Self
where D: Display + Send + Sync + 'static, Self: Sized,

Add the name of the value to the context of the error.

This method adds context to the Error so that it knows in which value the error occurred. It is perfectly fine to never use it, as long as you don’t mind cryptic errors.

Source

fn with_value<D>(self, f: impl FnOnce() -> D) -> Self
where D: Display + Send + Sync + 'static, Self: Sized,

The same as Context::value but lazily-evaluated.

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

Source§

fn module<D>(self, name: D) -> Self
where D: Display + Send + Sync + 'static, Self: Sized,

Source§

fn with_module<D>(self, f: impl FnOnce() -> D) -> Self
where D: Display + Send + Sync + 'static,

Source§

fn value<D>(self, name: D) -> Self
where D: Display + Send + Sync + 'static, Self: Sized,

Source§

fn with_value<D>(self, f: impl FnOnce() -> D) -> Self
where D: Display + Send + Sync + 'static, Self: Sized,

Implementors§