Remove unnecessary collects
@@ -130,14 +130,14 @@ fn gen_variant_match(ident: &Ident, tag: VmTag, variant: &Variant) -> TokenStrea
// of the field to get the content from Data::get_variant;
// the data variable was assigned in the function body above
Fields::Unnamed(FieldsUnnamed { unnamed, .. }) => {
- let cons = gen_tuple_cons(unnamed.into_iter().collect());
+ let cons = gen_tuple_cons(unnamed);
quote! {
#tag => #ident::#variant_ident#cons
}
}
Fields::Named(FieldsNamed { named, .. }) => {
- let cons = gen_struct_cons(named.into_iter().collect());
+ let cons = gen_struct_cons(named);
quote! {
#tag => #ident::#variant_ident#cons
@@ -146,11 +146,11 @@ fn gen_variant_match(ident: &Ident, tag: VmTag, variant: &Variant) -> TokenStrea
}
}
-fn gen_tuple_cons(fields: Vec<&Field>) -> TokenStream {
- let fields: Vec<_> = fields
- .into_iter()
- .enumerate()
- .map(|(idx, field)| {
+fn gen_tuple_cons<'a, I>(fields: I) -> TokenStream
+where
+ I: IntoIterator<Item = &'a Field>,
+{
+ let fields = fields.into_iter().enumerate().map(|(idx, field)| {
let field_ty = &field.ty;
quote! {
@@ -160,19 +160,18 @@ fn gen_tuple_cons(fields: Vec<&Field>) -> TokenStream {
panic!("Enum does not contain data at index '{}'. Do the type definitions match?", #idx)
}
}
- })
- .collect();
+ });
quote!{
(#(#fields),*)
}
}
-fn gen_struct_cons(fields: Vec<&Field>) -> TokenStream {
- let fields: Vec<_> = fields
- .into_iter()
- .enumerate()
- .map(|(idx, field)| {
+fn gen_struct_cons<'a, I>(fields: I) -> TokenStream
+where
+ I: IntoIterator<Item = &'a Field>,
+{
+ let fields = fields.into_iter().enumerate().map(|(idx, field)| {
let field_ty = &field.ty;
let field_ident = field
.ident
@@ -186,8 +185,7 @@ fn gen_struct_cons(fields: Vec<&Field>) -> TokenStream {
panic!("Enum does not contain data at index '{}'. Do the type definitions match?", #idx)
}
}
- })
- .collect();
+ });
quote!{
{#(#fields),*}
