Skip to main content

Context

Trait Context 

Source
pub trait Context<T> {
    // Required methods
    fn context(self, context: impl Display) -> Result<T>;
    fn with_context<C: Display>(self, context: impl FnOnce() -> C) -> Result<T>;
}
Expand description

Adds .context(..) to any Result whose error converts into Error, the way anyhow::Context does — but preserving the ErrorKind when the error already is a Rainier error, so adding context to a 404 does not silently turn it into a 500.

Required Methods§

Source

fn context(self, context: impl Display) -> Result<T>

Prefix the error message with context.

Source

fn with_context<C: Display>(self, context: impl FnOnce() -> C) -> Result<T>

Prefix the error message with a lazily built context.

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> Context<T> for Option<T>

Source§

fn context(self, context: impl Display) -> Result<T>

Source§

fn with_context<C: Display>(self, context: impl FnOnce() -> C) -> Result<T>

Implementors§

Source§

impl<T, E> Context<T> for Result<T, E>
where E: Into<Error>,