I have a macro_rules!, let's call it m!(). I want the following code to print a,b,c,d,e:
fn main() {
println!("{}", m!(a, b, c, d, e));
}
So I tried:
macro_rules! m {
{ $($i:ident),+ } => { stringify!($($i),+) };
}
But then there are spaces after the commas: a, b, c, d, e.
Then I tried:
macro_rules! m {
{ $($i:ident),+ } => { concat!($(stringify!($i))",",+) };
}
Which didn't compile because there can be only one token as a separator. But even the following does not compile, for a reason I don't understand:
macro_rules! m {
{ $($i:ident),+ } => { concat!($(stringify!($i))","+) };
}
Seems like you cannot have string as a separator at all.
Then I tried:
macro_rules! m {
{ $($i:ident),+ } => { concat!($(stringify!($i), ","),+) };
}
But then there is a comma after the last item: a,b,c,d,e,.
Any ideas?