fn-error-context 0.1.0

An attribute macro to add context to errors from a function.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use fn_error_context::context;

struct Foo(u32);

impl Foo {
    #[context("context")]
    fn do_stuff(&self) -> anyhow::Result<()> {
        anyhow::bail!("error {}", self.0)
    }
}

fn main() {
    assert_eq!(
        format!("{:#}", Foo(1).do_stuff().unwrap_err()),
        "context: error 1"
    );
}