macro_rules! match_err { ( $any:expr, $ty:ident, { $( $variant:ident $( ( $($inner:ident),* ) )? => $arm:expr ),*, _ => $default:expr } ) => { ... }; ( $any:expr, $ty:ident, { $( $variant:ident $( ( $($inner:ident),* ) )? => $arm:expr ),* $(,)? }) => { ... }; }
Expand description
Matches the error against an enum-like error type by hiding the usage of downcast_ref method
§Examples
use match_err::*;
use anyhow::anyhow;
#[derive(thiserror::Error, Debug)]
enum Error {
#[error("not found")]
NotFound,
#[error("custom: {0}")]
Custom(String),
}
let err = anyhow!(Error::NotFound);
match_err!(err, Error, {
NotFound => assert!(true),
Custom(msg) => assert!(false),
_ => assert!(false)
})