all_tuples_enumerated

Macro all_tuples_enumerated 

Source
all_tuples_enumerated!() { /* proc-macro */ }
Expand description

A variant of all_tuples! that enumerates its output.

In particular, the tuples used by the inner macro will themselves be composed of tuples which contain the index.

For example, with a single parameter:


trait Squawk {
    fn squawk(&self);
}

// If every type in a tuple is `Squawk`, the tuple can squawk by having its
// constituents squawk sequentially:
macro_rules! impl_squawk {
    ($(($n:tt, $T:ident)),*) => {
        impl<$($T: Squawk),*> Squawk for ($($T,)*) {
            fn squawk(&self) {
                $(
                    self.$n.squawk();
                )*
            }
        }
    };
}

all_tuples_enumerated!(impl_squawk, 1, 15, T);
// impl_squawk!((0, T0));
// impl_squawk!((0, T0), (1, T1));
// ..
// impl_squawk!((0, T0) .. (14, T14));

With multiple parameters, the result is similar, but with the additional parameters included in each tuple; e.g.:

all_tuples_enumerated!(impl_squawk, 1, 15, P, p);
// impl_squawk!((0, P0, p0));
// impl_squawk!((0, P0, p0), (1, P1, p1));
// ..
// impl_squawk!((0, P0, p0) .. (14, P14, p14));