Skip to main content

ErrCtxExt

Trait ErrCtxExt 

Source
pub trait ErrCtxExt<T>: Sized {
    // Required methods
    fn err_ctx(self, context: &'static str) -> Result<T>;
    fn err_ctx_with(self, context: String) -> Result<T>;
}
Expand description

Substrate extension trait over Result<T, E> for any E: std::fmt::Display — the ONE substrate owner of the generic .map_err(|e| anyhow::anyhow!("<ctx>: {e}")) display-prefix wrap-shape for consumers whose source error is a bare Display type NOT already covered by a per-error-type flatten-wrap peer. See the module docs for the specialized-peer partition + the naming rationale (why err_ctx and not context).

Required Methods§

Source

fn err_ctx(self, context: &'static str) -> Result<T>

Wrap the source error (if any) with a static context prefix, producing an anyhow::Result whose error Display reads exactly "<context>: <source display>".

Source

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

Owned-string peer of Self::err_ctx — the escape hatch for consumers that compose the context slug via format!.

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> ErrCtxExt<T> for Result<T, E>
where E: Display,

Source§

fn err_ctx(self, context: &'static str) -> Result<T>

Source§

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

Implementors§