Skip to main content

ContextExt

Trait ContextExt 

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

Adds .context(..) / .with_context(..) to Result<T> and Option<T>.

On a Result it wraps the existing error; on an Option a None becomes a client error carrying the context message.

Required Methods§

Source

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

Attaches context to the error path.

Source

fn with_context<C: Into<String>, F: FnOnce() -> C>(self, f: F) -> Result<T>

Attaches a lazily-built context message to the error path.

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

Source§

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

Source§

fn with_context<C: Into<String>, F: FnOnce() -> C>(self, f: F) -> Result<T>

Implementors§

Source§

impl<T> ContextExt<T> for Result<T>