Skip to content

Commit 46527c1

Browse files
committed
More macro cleverness (2) avoid always-same parameter
1 parent 0d5f4a3 commit 46527c1

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/tuple_impl.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ macro_rules! count_ident{
250250
}
251251

252252
macro_rules! impl_tuple_collect {
253-
($A:ident ; $($X:ident),* ; $($Y:ident),* ; $($Y_rev:ident),*) => (
254-
impl<$A> TupleCollect for ($($X),*,) {
255-
type Item = $A;
256-
type Buffer = [Option<$A>; count_ident!($($Y,)*) - 1];
253+
($($X:ident),* ; $($Y:ident),* ; $($Y_rev:ident),*) => (
254+
impl<A> TupleCollect for ($($X),*,) {
255+
type Item = A;
256+
type Buffer = [Option<A>; count_ident!($($Y,)*) - 1];
257257

258258
#[allow(unused_assignments, unused_mut)]
259259
fn collect_from_iter<I>(iter: I, buf: &mut Self::Buffer) -> Option<Self>
260-
where I: IntoIterator<Item = $A>
260+
where I: IntoIterator<Item = A>
261261
{
262262
let mut iter = iter.into_iter();
263263
$(
@@ -286,7 +286,7 @@ macro_rules! impl_tuple_collect {
286286
}
287287

288288
fn collect_from_iter_no_buf<I>(iter: I) -> Option<Self>
289-
where I: IntoIterator<Item = $A>
289+
where I: IntoIterator<Item = A>
290290
{
291291
let mut iter = iter.into_iter();
292292

@@ -299,7 +299,7 @@ macro_rules! impl_tuple_collect {
299299
count_ident!($($Y,)*)
300300
}
301301

302-
fn left_shift_push(&mut self, item: $A) {
302+
fn left_shift_push(&mut self, item: A) {
303303
use std::mem::replace;
304304

305305
let &mut ($(ref mut $Y),*,) = self;
@@ -317,22 +317,22 @@ macro_rules! impl_tuple_collect {
317317
// use itertools::Itertools;
318318
//
319319
// for i in 1..=12 {
320-
// println!("impl_tuple_collect!(A; {ty}; {idents}; {rev_idents});",
320+
// println!("impl_tuple_collect!({ty}; {idents}; {rev_idents});",
321321
// ty=iter::repeat("A").take(i).join(", "),
322322
// idents=('a'..='z').take(i).join(", "),
323323
// rev_idents=('a'..='z').take(i).collect_vec().into_iter().rev().join(", ")
324324
// );
325325
// }
326326
// It could probably be replaced by a bit more macro cleverness.
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);
327+
impl_tuple_collect!(A; a; a);
328+
impl_tuple_collect!(A, A; a, b; b, a);
329+
impl_tuple_collect!(A, A, A; a, b, c; c, b, a);
330+
impl_tuple_collect!(A, A, A, A; a, b, c, d; d, c, b, a);
331+
impl_tuple_collect!(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, b, c, d, e, f; f, e, d, c, b, a);
333+
impl_tuple_collect!(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, 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, 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, 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, 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, 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

Comments
 (0)