Skip to main content

Context

Trait Context 

Source
pub trait Context<T> {
    // Required methods
    fn context(self, context: impl Into<String>) -> Result<T, CaptureError>;
    fn with_context<S: Into<String>>(
        self,
        f: impl FnOnce() -> S,
    ) -> Result<T, CaptureError>;
}
Expand description

Attach context to a fallible value, mapping its error into CaptureError::Backend while preserving the original cause. Mirrors anyhow::Context, so a call site only has to import crate::error::Context instead of anyhow::Context.

Required Methods§

Source

fn context(self, context: impl Into<String>) -> Result<T, CaptureError>

Wrap the error with a fixed context message.

Source

fn with_context<S: Into<String>>( self, f: impl FnOnce() -> S, ) -> Result<T, CaptureError>

Wrap the error with a lazily-built context message (only computed on error).

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

Source§

fn context(self, context: impl Into<String>) -> Result<T, CaptureError>

Source§

fn with_context<S: Into<String>>( self, f: impl FnOnce() -> S, ) -> Result<T, CaptureError>

Implementors§

Source§

impl<T, E: StdError + Send + Sync + 'static> Context<T> for Result<T, E>