zkat/miette

Implement `WrapError` for `Option`

Closed this issue · 1 comments

anyhow implements it's Context trait on options. This helps avoid some boilerplate:

use anyhow::Context;

let map = HashMap::from([("a", 1), ("b", 2), ("c", 3)]);
let _ = map.get("d").with_context(|| format!("Key 'd' was missing from map: {map:?}"))?;

Currently the best way to do this with miette is by using a let else then bail!:

use miette::bail;

let map = HashMap::from([("a", 1), ("b", 2), ("c", 3)]);
let Some(_) = map.get("d") else {
    bail!("Key 'd' was missing from map: {map:?}"));
};

I'm willing to implement this if desired

zkat commented

sounds good to me! go for it!