macro_rules! impl_component {
// Empty case to end the recursion
($n:expr ;) => {};
// Match the current count, the current type, and whatever else comes after
($n:expr ; $t:ty $(, $rest:tt)*) => {
impl Component for $t {
fn index(&self) -> usize { $n }
}
// Recurse, incrementing counter and only passing the remaining params
impl_component!($n + 1; $($rest),*);
};
// For the first recursion, set the counter initial value to zero
($($types:tt),+) => { impl_component!(0; $($types),*); };
}
impl_component!(Foo, Bar, Baz);