Skip to main content

DecodeContext

Trait DecodeContext 

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

Adds the context of a decoding step to a failed result.

Implemented for every Result whose error converts into DecodeError, so it applies to results of Decodable calls and to std::io::Result. Its method names match anyhow::Context’s; where both traits are in scope, call it as DecodeContext::context(result, ..) to avoid the clash.

Required Methods§

Source

fn context<C>(self, context: C) -> Result<T, DecodeError>
where C: Display,

Wraps the error in context.

Source

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

Wraps the error in the context produced by context, which only runs on failure.

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, E> DecodeContext<T> for Result<T, E>
where E: Into<DecodeError>,

Source§

fn context<C>(self, context: C) -> Result<T, DecodeError>
where C: Display,

Source§

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

Implementors§