anyhow_auto_context

Macro auto_context

Source
macro_rules! auto_context {
    ($result:expr_2021) => { ... };
}
Expand description

Adds automatic anyhow context based on scope and location


let expected_some: Option<()> = None;
let result = auto_context!(expected_some);
assert!(result.unwrap_err().to_string().starts_with("expected_some in"));

let expected_ok: anyhow::Result<()> = Err(anyhow::anyhow!("foo_err"));
let result = auto_context!(expected_ok);
assert!(result.unwrap_err().to_string().starts_with("expected_ok in"));