macro_rules! match_err {
(
$expr:expr
$(, type<$ty:ty>($pat:pat) => $handler:expr)*
$(, else($default_pat:pat) => $default_handler:expr)?
$(,)?
) => { ... };
}Expand description
Match an eyre::Report against multiple error types and patterns.
ยงExample
use agglayer_errors::match_err;
use eyre::Context as _;
#[derive(Debug, thiserror::Error)]
#[error("Foo")]
struct Foo;
#[derive(Debug, thiserror::Error)]
#[error("Bar")]
struct Bar(&'static str);
let err: eyre::Report = Foo.into();
let s = match_err!(err,
type<Foo>(_) => "foo".to_string(),
type<Bar>(Bar("foo")) => "bar/foo".to_string(),
type<Bar>(Bar(s)) => format!("bar({s})"),
else(_) => "other".to_string(),
);