errify_with

Attribute Macro errify_with 

Source
#[errify_with]
Expand description

Macro that provides lazy error context on entire function. Supports async functions.

Constraint is F: FnOnce() -> impl Display + Send + Sync + 'static and E: WrapErr.

§Syntax

#[errify_with( $closure:expr | $func:ident )]

§Usage example

§Closure

use errify::errify_with;

#[errify_with(|| "Custom error context from closure")]
fn func(arg: i32) -> Result<(), CustomError> {
    // ...
}

§Function

use errify::errify_with;

fn context_provider() -> impl Display { "Context from function" }

#[errify_with(context_provider)]
fn func(arg: i32) -> Result<(), CustomError> {
    // ...
}