anyhow-auto-context 1.0.0

Automatic context for anyhow errors based on scope and location
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Additional context
use anyhow::Result;
use anyhow_auto_context::auto_context;

fn main() -> Result<()> {
    for i in 1..100 {
        auto_context!(not_42(i), "i = {i}")?;
    }
    Ok(())
}

fn not_42(n: usize) -> Result<()> {
    anyhow::ensure!(n != 42, "Unexpected 42");
    Ok(())
}