Trait ErrorContext

Source
pub trait ErrorContext<T, K, E> {
    // Required methods
    fn err_context(self, kind: K) -> Result<T, E>;
    fn err_context_with(self, kind: impl FnOnce() -> K) -> Result<T, E>;
}
Expand description

Helper trait to add context to errors.

Most likely you want to use the trait of the same name and API generated by declare_error_type.

Required Methods§

Source

fn err_context(self, kind: K) -> Result<T, E>

Add an error kind to the top of the error backtrace.

Source

fn err_context_with(self, kind: impl FnOnce() -> K) -> Result<T, E>

Add an error kind returned by a function to the top of the error backtrace. The function should only be called if self is indeed 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, K, E, OE> ErrorContext<T, K, E> for Result<T, OE>
where OE: Into<E>, E: ErrorType<ErrorKind = K>,

Source§

fn err_context(self, kind: K) -> Result<T, E>

Source§

fn err_context_with(self, f: impl FnOnce() -> K) -> Result<T, E>

Implementors§