Skip to main content

ContextExt

Trait ContextExt 

Source
pub trait ContextExt<T> {
    // Required methods
    fn context(self, message: impl Into<Cow<'static, str>>) -> TestResult<T>;
    fn with_context<F, S>(self, f: F) -> TestResult<T>
       where F: FnOnce() -> S,
             S: Into<Cow<'static, str>>;
}
Expand description

Attaches context to the failure path of a Result or the None of an Option.

Required Methods§

Source

fn context(self, message: impl Into<Cow<'static, str>>) -> TestResult<T>

Adds a context frame describing the operation that was being attempted.

On the success path the value is returned unchanged.

Source

fn with_context<F, S>(self, f: F) -> TestResult<T>
where F: FnOnce() -> S, S: Into<Cow<'static, str>>,

Like context, but the message is computed by f, which runs only on the failure path.

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

Source§

fn context(self, message: impl Into<Cow<'static, str>>) -> TestResult<T>

Source§

fn with_context<F, S>(self, f: F) -> TestResult<T>
where F: FnOnce() -> S, S: Into<Cow<'static, str>>,

Source§

impl<T, E> ContextExt<T> for Result<T, E>
where E: Error + Send + Sync + 'static,

Source§

fn context(self, message: impl Into<Cow<'static, str>>) -> TestResult<T>

Source§

fn with_context<F, S>(self, f: F) -> TestResult<T>
where F: FnOnce() -> S, S: Into<Cow<'static, str>>,

Implementors§