fn-error-context 0.2.1

An attribute macro to add context to errors from a function.
Documentation
use fn_error_context::context;

struct Foo(u32);

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

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

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