Hi!
I have the following macro
macro_rules! must {
($expression:expr, $pattern:pat_param, $e:expr ) => {
match $expression {
$pattern => $e,
_ => panic!("oops"),
}
};
}
enum A {
A(u64),
B(u64),
}
fn main() {
let a = A::A(1);
let d = must!(a, A::A(c), c);
println!("{}", d);
// will panic
let e = must!(a, A::B(b), b);
}
Is there any way to avoid specificing the last argument in the macro? I.e. the $e:expr
and have to somehow figure it out from the pattern?
So when I use the macro I don't have write must!(a, A::B(b), b)
but just write must(a, A::B(b)
instead.