pub trait Contextable {
    // Required methods
    fn context(self, c: impl Display) -> Self;
    fn with_context<C, F>(self, c: F) -> Self
       where C: Display,
             F: FnOnce() -> C;
}

Required Methods§

source

fn context(self, c: impl Display) -> Self

Add a context string c to a Result or Error

Example: foo().context(“calling foo”)?;

source

fn with_context<C, F>(self, c: F) -> Selfwhere C: Display, F: FnOnce() -> C,

Like context(), but evaluate the context string lazily

Use this if it’s expensive to generate, like a format!() call.

Implementations on Foreign Types§

source§

impl<T> Contextable for Result<T>

source§

fn context(self, c: impl Display) -> Self

source§

fn with_context<C, F>(self, c: F) -> Selfwhere C: Display, F: FnOnce() -> C,

source§

impl Contextable for Error

source§

fn context(self, c: impl Display) -> Self

source§

fn with_context<C, F>(self, c: F) -> Selfwhere C: Display, F: FnOnce() -> C,

Implementors§