@@ -244,11 +244,16 @@ pub trait TupleCollect: Sized {
244
244
fn left_shift_push ( & mut self , item : Self :: Item ) ;
245
245
}
246
246
247
+ macro_rules! count_ident{
248
+ ( ) => { 0 } ;
249
+ ( $i0: ident, $( $i: ident, ) * ) => { 1 + count_ident!( $( $i, ) * ) } ;
250
+ }
251
+
247
252
macro_rules! impl_tuple_collect {
248
- ( $N : expr ; $ A: ident ; $( $X: ident) ,* ; $( $Y: ident) ,* ; $( $Y_rev: ident) ,* ) => (
253
+ ( $A: ident ; $( $X: ident) ,* ; $( $Y: ident) ,* ; $( $Y_rev: ident) ,* ) => (
249
254
impl <$A> TupleCollect for ( $( $X) ,* , ) {
250
255
type Item = $A;
251
- type Buffer = [ Option <$A>; $N - 1 ] ;
256
+ type Buffer = [ Option <$A>; count_ident! ( $ ( $Y , ) * ) - 1 ] ;
252
257
253
258
#[ allow( unused_assignments, unused_mut) ]
254
259
fn collect_from_iter<I >( iter: I , buf: & mut Self :: Buffer ) -> Option <Self >
@@ -291,7 +296,7 @@ macro_rules! impl_tuple_collect {
291
296
}
292
297
293
298
fn num_items( ) -> usize {
294
- $N
299
+ count_ident! ( $ ( $Y , ) * )
295
300
}
296
301
297
302
fn left_shift_push( & mut self , item: $A) {
@@ -312,23 +317,22 @@ macro_rules! impl_tuple_collect {
312
317
// use itertools::Itertools;
313
318
//
314
319
// for i in 1..=12 {
315
- // println!("impl_tuple_collect!({arity}; A; {ty}; {idents}; {rev_idents});",
316
- // arity=i,
320
+ // println!("impl_tuple_collect!(A; {ty}; {idents}; {rev_idents});",
317
321
// ty=iter::repeat("A").take(i).join(", "),
318
322
// idents=('a'..='z').take(i).join(", "),
319
323
// rev_idents=('a'..='z').take(i).collect_vec().into_iter().rev().join(", ")
320
324
// );
321
325
// }
322
326
// It could probably be replaced by a bit more macro cleverness.
323
- impl_tuple_collect ! ( 1 ; A ; A ; a; a) ;
324
- impl_tuple_collect ! ( 2 ; A ; A , A ; a, b; b, a) ;
325
- impl_tuple_collect ! ( 3 ; A ; A , A , A ; a, b, c; c, b, a) ;
326
- impl_tuple_collect ! ( 4 ; A ; A , A , A , A ; a, b, c, d; d, c, b, a) ;
327
- impl_tuple_collect ! ( 5 ; A ; A , A , A , A , A ; a, b, c, d, e; e, d, c, b, a) ;
328
- impl_tuple_collect ! ( 6 ; A ; A , A , A , A , A , A ; a, b, c, d, e, f; f, e, d, c, b, a) ;
329
- impl_tuple_collect ! ( 7 ; A ; A , A , A , A , A , A , A ; a, b, c, d, e, f, g; g, f, e, d, c, b, a) ;
330
- impl_tuple_collect ! ( 8 ; A ; A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h; h, g, f, e, d, c, b, a) ;
331
- impl_tuple_collect ! ( 9 ; A ; A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i; i, h, g, f, e, d, c, b, a) ;
332
- impl_tuple_collect ! ( 10 ; A ; A , A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i, j; j, i, h, g, f, e, d, c, b, a) ;
333
- impl_tuple_collect ! ( 11 ; A ; A , A , A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i, j, k; k, j, i, h, g, f, e, d, c, b, a) ;
334
- impl_tuple_collect ! ( 12 ; A ; A , A , A , A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i, j, k, l; l, k, j, i, h, g, f, e, d, c, b, a) ;
327
+ impl_tuple_collect ! ( A ; A ; a; a) ;
328
+ impl_tuple_collect ! ( A ; A , A ; a, b; b, a) ;
329
+ impl_tuple_collect ! ( A ; A , A , A ; a, b, c; c, b, a) ;
330
+ impl_tuple_collect ! ( A ; A , A , A , A ; a, b, c, d; d, c, b, a) ;
331
+ impl_tuple_collect ! ( A ; A , A , A , A , A ; a, b, c, d, e; e, d, c, b, a) ;
332
+ impl_tuple_collect ! ( A ; A , A , A , A , A , A ; a, b, c, d, e, f; f, e, d, c, b, a) ;
333
+ impl_tuple_collect ! ( A ; A , A , A , A , A , A , A ; a, b, c, d, e, f, g; g, f, e, d, c, b, a) ;
334
+ impl_tuple_collect ! ( A ; A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h; h, g, f, e, d, c, b, a) ;
335
+ impl_tuple_collect ! ( A ; A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i; i, h, g, f, e, d, c, b, a) ;
336
+ impl_tuple_collect ! ( A ; A , A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i, j; j, i, h, g, f, e, d, c, b, a) ;
337
+ impl_tuple_collect ! ( A ; A , A , A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i, j, k; k, j, i, h, g, f, e, d, c, b, a) ;
338
+ impl_tuple_collect ! ( A ; A , A , A , A , A , A , A , A , A , A , A , A ; a, b, c, d, e, f, g, h, i, j, k, l; l, k, j, i, h, g, f, e, d, c, b, a) ;
0 commit comments