I would like to define a macro callmethat can be applied as follows.
fn main() {
let a=4;
let b=5;
callme!(
a (b) => { a+b } ;
a (b) => { a*b } ;
a (b) ~ C
);
}
I do not know how to get a working macro definition for callme. I'm currently trying to do something like this:
macro_rules! callme {
(
$($A: ident ($B: ident) => {$E: expr}) ; *
) => (
$(
println!("{:?} {:?} {:?}", $A, $B, $E);
) *
);
(
$($A: ident ($B: ident) ~ $Q: ident) ; *
) => (
$(
println!("We got {:?} . {:?} . {:?}", $A, $B, $Q);
) *
);
}
This does not work because I cannot use both cases of syntax at once.
source
share