What is the best way to get the length of a repeating macro argument as an integer in the expansion?
The one I'm currently using is the following:
macro_rules! test {
($($name:ident : $ty:ty),+) => {
struct X {
$($name: $ty),+
}
impl X {
fn len(&self) -> usize {
[$(stringify!($name)),+].len()
}
}
}
}
i.e. construct an array of static strings and take its len(). In release mode it's properly optimized out, but in debug mode it carries the whole useless static array around. Is there a nicer way?