You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)]);letSome(_) = map.get("d")else{
bail!("Key 'd' was missing from map: {map:?}"));};
I'm willing to implement this if desired
The text was updated successfully, but these errors were encountered:
Implement `WrapError` for `Option<T>`. This is inline with `anyhow` that
also implements `Context` for `Option<T>`.
The implementation requires us to introduce a `DisplayError` internal
only type, that creates an error from a type that only implements
`Display` (`Report::from_adhoc` requires the type to also implement
`Debug`, but `WrapError` only requires it to implement `Display`).
For this I copied `MessageError` and adapted it to implement `Debug`
using the underlying type's `Display` impl. This is a bit of a hack, but
anyhow does [something similar][1].
Closeszkat#408
[1]: https://docs.rs/anyhow/latest/src/anyhow/wrapper.rs.html#34
anyhow
implements it'sContext
trait on options. This helps avoid some boilerplate:Currently the best way to do this with
miette
is by using alet else
thenbail!
:I'm willing to implement this if desired
The text was updated successfully, but these errors were encountered: