Trait Context

Source
pub trait Context: Sized {
    type Ok;
    type Error: Error;

    // Required method
    fn with_context<C>(
        self,
        context: impl FnOnce() -> C,
    ) -> Result<Self::Ok, Self::Error>
       where C: Display;

    // Provided method
    fn context<C>(self, context: C) -> Result<Self::Ok, Self::Error>
       where C: Display { ... }
}
Expand description

Adapter for providing context on Result

Required Associated Types§

Required Methods§

Source

fn with_context<C>( self, context: impl FnOnce() -> C, ) -> Result<Self::Ok, Self::Error>
where C: Display,

Wrap Err in context by calling given function

Provided Methods§

Source

fn context<C>(self, context: C) -> Result<Self::Ok, Self::Error>
where C: Display,

Wrap Err in given context

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

Source§

type Ok = T

Source§

type Error = StringError

Source§

fn with_context<C>( self, context: impl FnOnce() -> C, ) -> Result<Self::Ok, Self::Error>
where C: Display,

Source§

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

Source§

type Ok = T

Source§

type Error = E

Source§

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

Implementors§