Context

Trait Context 

Source
pub trait Context<D> {
    type Output;

    // Required methods
    fn context(self, msg: &'static str) -> Self::Output;
    fn with_context<F, M>(self, with_msg: F) -> Self::Output
       where F: FnOnce() -> M,
             M: Display;
}
Expand description

Context for Result-like types

Required Associated Types§

Required Methods§

Source

fn context(self, msg: &'static str) -> Self::Output

Adds context to this result, if it’s an error

Source

fn with_context<F, M>(self, with_msg: F) -> Self::Output
where F: FnOnce() -> M, M: Display,

Adds context to this result lazily, if it’s an 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, D> Context<D> for Option<T>
where D: Default,

Source§

type Output = Result<T, AppError<D>>

Source§

fn context(self, msg: &'static str) -> Self::Output

Source§

fn with_context<F, M>(self, with_msg: F) -> Self::Output
where F: FnOnce() -> M, M: Display,

Source§

impl<T, D> Context<D> for Result<T, &AppError<D>>
where D: Default,

Source§

type Output = Result<T, AppError<D>>

Source§

fn context(self, msg: &'static str) -> Self::Output

Source§

fn with_context<F, M>(self, with_msg: F) -> Self::Output
where F: FnOnce() -> M, M: Display,

Source§

impl<T, D> Context<D> for Result<T, &mut AppError<D>>
where D: Default,

Source§

type Output = Result<T, AppError<D>>

Source§

fn context(self, msg: &'static str) -> Self::Output

Source§

fn with_context<F, M>(self, with_msg: F) -> Self::Output
where F: FnOnce() -> M, M: Display,

Source§

impl<T, D> Context<D> for Result<T, AppError<D>>
where D: Default,

Source§

type Output = Result<T, AppError<D>>

Source§

fn context(self, msg: &'static str) -> Self::Output

Source§

fn with_context<F, M>(self, with_msg: F) -> Self::Output
where F: FnOnce() -> M, M: Display,

Source§

impl<T, E, D> Context<D> for Result<T, E>
where E: StdError, D: Default,

Source§

type Output = Result<T, AppError<D>>

Source§

fn context(self, msg: &'static str) -> Self::Output

Source§

fn with_context<F, M>(self, with_msg: F) -> Self::Output
where F: FnOnce() -> M, M: Display,

Implementors§