Skip to main content

ErrorContext

Trait ErrorContext 

Source
pub trait ErrorContext {
    // Required method
    fn with_context<C, F>(self, context: F) -> Self
       where C: Context,
             F: FnOnce() -> C;
}
Expand description

Propose additional error context for the error to consider collecting.

The information provided to ErrorContext should be thought of as debugging information only. You should never depend on any of this information logically.

Whether or not this context information is collected depends on how you define your Error type.

Required Methods§

Source

fn with_context<C, F>(self, context: F) -> Self
where C: Context, F: FnOnce() -> C,

Provide human-readable context about why an error occurred.

Context is collected if the error supports it with the proper envelopes. If collected, it will be printed in stack order (first piece of context added prints first, followed by the next, etc).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, E: ErrorContext> ErrorContext for Result<T, E>

Source§

fn with_context<C, F>(self, context: F) -> Self
where C: Context, F: FnOnce() -> C,

Source§

impl<T: ErrorContext> ErrorContext for Option<T>

Source§

fn with_context<C, F>(self, context: F) -> Self
where C: Context, F: FnOnce() -> C,

Implementors§

Source§

impl<K: ErrorKind> ErrorContext for Described<K>

Available on crate feature alloc only.
Source§

impl<K: ErrorKind> ErrorContext for Diagnostic<K>

Available on crate feature alloc only.
Source§

impl<K: ErrorKind> ErrorContext for K

Source§

impl<K: ErrorKind> ErrorContext for Located<K>