From e170e02d54ce845779f2d12c73264a73e859eb2d Mon Sep 17 00:00:00 2001 From: Benjamin Brienen Date: Thu, 26 Dec 2024 18:44:41 -0500 Subject: [PATCH] prefer collect into Vec --- src/lib.rs | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dfc5775..13a6c6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,15 +163,15 @@ impl Parse for AllTuples { pub fn all_tuples(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as AllTuples); let len = 1 + input.end - input.start; - let mut ident_tuples = Vec::with_capacity(len); - for i in 0..=len { - let idents = input - .idents - .iter() - .map(|ident| format_ident!("{}{}", ident, i)); - ident_tuples.push(to_ident_tuple(idents, input.idents.len())); - } - + let ident_tuples = (0..=len) + .map(|i| { + let idents = input + .idents + .iter() + .map(|ident| format_ident!("{}{}", ident, i)); + to_ident_tuple(idents, input.idents.len()) + }) + .collect::>(); let macro_ident = &input.macro_ident; let invocations = (input.start..=input.end).map(|i| { let ident_tuples = choose_ident_tuples(&input, &ident_tuples, i); @@ -238,15 +238,15 @@ pub fn all_tuples(input: TokenStream) -> TokenStream { pub fn all_tuples_enumerated(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as AllTuples); let len = 1 + input.end - input.start; - let mut ident_tuples = Vec::with_capacity(len); - for i in 0..=len { - let idents = input - .idents - .iter() - .map(|ident| format_ident!("{}{}", ident, i)); - ident_tuples.push(to_ident_tuple_enumerated(idents, i)); - } - + let ident_tuples = (0..=len) + .map(|i| { + let idents = input + .idents + .iter() + .map(|ident| format_ident!("{}{}", ident, i)); + to_ident_tuple_enumerated(idents, input.idents.len()) + }) + .collect::>(); let macro_ident = &input.macro_ident; let invocations = (input.start..=input.end).map(|i| { let ident_tuples = choose_ident_tuples_enumerated(&input, &ident_tuples, i); @@ -380,14 +380,15 @@ pub fn all_tuples_enumerated(input: TokenStream) -> TokenStream { pub fn all_tuples_with_size(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as AllTuples); let len = 1 + input.end - input.start; - let mut ident_tuples = Vec::with_capacity(len); - for i in 0..=len { - let idents = input - .idents - .iter() - .map(|ident| format_ident!("{}{}", ident, i)); - ident_tuples.push(to_ident_tuple(idents, input.idents.len())); - } + let ident_tuples = (0..=len) + .map(|i| { + let idents = input + .idents + .iter() + .map(|ident| format_ident!("{}{}", ident, i)); + to_ident_tuple(idents, input.idents.len()) + }) + .collect::>(); let macro_ident = &input.macro_ident; let invocations = (input.start..=input.end).map(|i| { let ident_tuples = choose_ident_tuples(&input, &ident_tuples, i);