The code below does not work
macro_rules! vec_with_keys {
($x:literal $sep:tt $y:literal $($tail:tt)*) => {
{
println!("Value pair received: ({}, {})", $x,$y);
println!("Inside rule 1: {}", stringify!(concat!($($tail)*)));
vec_with_keys!($($tail)*); // here is the error
}
};
(,$($tail:tt)*)=>{
{
println!("Inside rule 2: {}", stringify!(concat!($($tail)*)));
vec_with_keys!($($tail)*);
}
};
($x:literal)=>{panic!("Incorrect number of arguments");};
}
fn main(){
vec_with_keys![9:1,8:9];
}
The above code gives error missing tokens in macro arguments. However, the print statement shows that tokens are present. Not sure why it is not passed in macro invocation
This one works
macro_rules! vec_with_keys {
($x:literal $sep:tt $y:literal $($tail:tt)*) => {
{
println!("Value pair received: ({}, {})", $x,$y);
println!("Inside rule 1: {}", stringify!(concat!($($tail)*)));
// vec_with_keys!($($tail)*);
}
};
(,$($tail:tt)*)=>{
{
println!("Inside rule 2: {}", stringify!(concat!($($tail)*)));
vec_with_keys!($($tail)*);
}
};
($x:literal)=>{panic!("Incorrect number of arguments");};
}
fn main(){
vec_with_keys![,8:9];
}