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§
Sourcefn context<C>(self, context: C) -> Result<T, DecodeError>where
C: Display,
fn context<C>(self, context: C) -> Result<T, DecodeError>where
C: Display,
Wraps the error in context.
Sourcefn with_context<C, F>(self, context: F) -> Result<T, DecodeError>
fn with_context<C, F>(self, context: F) -> Result<T, DecodeError>
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.