-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Description
In the course of implementing the Bounded trait for tuples (rust-num/num#89), I implemented a generic macro that runs the macro passed as its argument over every tuple type up to 20:
macro_rules! for_each_tuple_ {
( $m:ident !! ) => (
$m! { }
);
( $m:ident !! $h:ident, $($t:ident,)* ) => (
$m! { $h $($t)* }
for_each_tuple_! { $m !! $($t,)* }
);
}
macro_rules! for_each_tuple {
( $m:ident ) => (
for_each_tuple_! { $m !! A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, }
);
}
There are other instances of this pattern in Rust libraries; for instance, see
Line 239 in 8f5b5f9
macro_rules! impl_hash_tuple { |
Line 259 in 8f5b5f9
impl_hash_tuple! {} |
for_each_tuple!(impl_hash_tuple);
Would it make sense to put something like this somewhere in the Rust standard libraries, marked as unstable since it depends on defining macros? This would be useful for anyone implementing traits on tuples.
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.