@@ -251,9 +251,16 @@ macro_rules! count_ident{
251
251
macro_rules! ignore_ident{
252
252
( $id: ident, $( $t: tt) * ) => { $( $t) * } ;
253
253
}
254
+ macro_rules! rev_for_each_ident{
255
+ ( $m: ident, ) => { } ;
256
+ ( $m: ident, $i0: ident, $( $i: ident, ) * ) => {
257
+ rev_for_each_ident!( $m, $( $i, ) * ) ;
258
+ $m!( $i0) ;
259
+ } ;
260
+ }
254
261
255
262
macro_rules! impl_tuple_collect {
256
- ( $( $Y: ident) ,* ; $ ( $Y_rev : ident ) , * ) => (
263
+ ( $( $Y: ident) ,* ) => (
257
264
impl <A > TupleCollect for ( $( ignore_ident!( $Y, A ) , ) * ) {
258
265
type Item = A ;
259
266
type Buffer = [ Option <A >; count_ident!( $( $Y, ) * ) - 1 ] ;
@@ -302,39 +309,29 @@ macro_rules! impl_tuple_collect {
302
309
count_ident!( $( $Y, ) * )
303
310
}
304
311
305
- fn left_shift_push( & mut self , item: A ) {
312
+ fn left_shift_push( & mut self , mut item: A ) {
306
313
use std:: mem:: replace;
307
314
308
315
let & mut ( $( ref mut $Y) ,* , ) = self ;
309
- $(
310
- let item = replace( $Y_rev, item) ;
311
- ) *
316
+ macro_rules! replace_item{ ( $i: ident) => {
317
+ item = replace( $i, item) ;
318
+ } } ;
319
+ rev_for_each_ident!( replace_item, $( $Y, ) * ) ;
312
320
drop( item) ;
313
321
}
314
322
}
315
323
)
316
324
}
317
325
318
- // This snippet generates the twelve `impl_tuple_collect!` invocations:
319
- // use core::iter;
320
- // use itertools::Itertools;
321
- //
322
- // for i in 1..=12 {
323
- // println!("impl_tuple_collect!({idents}; {rev_idents});",
324
- // idents=('a'..='z').take(i).join(", "),
325
- // rev_idents=('a'..='z').take(i).collect_vec().into_iter().rev().join(", ")
326
- // );
327
- // }
328
- // It could probably be replaced by a bit more macro cleverness.
329
- impl_tuple_collect ! ( a; a) ;
330
- impl_tuple_collect ! ( a, b; b, a) ;
331
- impl_tuple_collect ! ( a, b, c; c, b, a) ;
332
- impl_tuple_collect ! ( a, b, c, d; d, c, b, a) ;
333
- impl_tuple_collect ! ( a, b, c, d, e; e, d, c, b, a) ;
334
- impl_tuple_collect ! ( a, b, c, d, e, f; f, e, d, c, b, a) ;
335
- impl_tuple_collect ! ( a, b, c, d, e, f, g; g, f, e, d, c, b, a) ;
336
- impl_tuple_collect ! ( a, b, c, d, e, f, g, h; h, g, f, e, d, c, b, a) ;
337
- impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i; i, h, g, f, e, d, c, b, a) ;
338
- impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i, j; j, i, h, g, f, e, d, c, b, a) ;
339
- impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i, j, k; k, j, i, h, g, f, e, d, c, b, a) ;
340
- impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i, j, k, l; l, k, j, i, h, g, f, e, d, c, b, a) ;
326
+ impl_tuple_collect ! ( a) ;
327
+ impl_tuple_collect ! ( a, b) ;
328
+ impl_tuple_collect ! ( a, b, c) ;
329
+ impl_tuple_collect ! ( a, b, c, d) ;
330
+ impl_tuple_collect ! ( a, b, c, d, e) ;
331
+ impl_tuple_collect ! ( a, b, c, d, e, f) ;
332
+ impl_tuple_collect ! ( a, b, c, d, e, f, g) ;
333
+ impl_tuple_collect ! ( a, b, c, d, e, f, g, h) ;
334
+ impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i) ;
335
+ impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i, j) ;
336
+ impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i, j, k) ;
337
+ impl_tuple_collect ! ( a, b, c, d, e, f, g, h, i, j, k, l) ;
0 commit comments