From 7831f6f1f7c7dddce1308738bd6d9ff654f71274 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Sat, 28 Oct 2023 18:35:32 -0400 Subject: [PATCH 1/2] Impl Copy, Eq, and FusedIterator for EnumIter iterators --- strum_macros/src/macros/enum_iter.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/strum_macros/src/macros/enum_iter.rs b/strum_macros/src/macros/enum_iter.rs index 0e700aa..8497404 100644 --- a/strum_macros/src/macros/enum_iter.rs +++ b/strum_macros/src/macros/enum_iter.rs @@ -71,9 +71,7 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result { Ok(quote! { #[doc = #doc_comment] - #[allow( - missing_copy_implementations, - )] + #[derive(Clone, Copy, Eq, PartialEq)] #vis struct #iter_name #ty_generics { idx: usize, back_idx: usize, @@ -159,14 +157,6 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result { } } - impl #impl_generics Clone for #iter_name #ty_generics #where_clause { - fn clone(&self) -> #iter_name #ty_generics { - #iter_name { - idx: self.idx, - back_idx: self.back_idx, - marker: self.marker.clone(), - } - } - } + impl #impl_generics ::core::iter::FusedIterator for #iter_name #ty_generics #where_clause { } }) } From 84cf8d2a321ec27ec49c67b3fb19d082b6d9668a Mon Sep 17 00:00:00 2001 From: Peter Glotfelty Date: Sun, 29 Oct 2023 12:29:44 -0700 Subject: [PATCH 2/2] Support FusedIteratorOnly --- strum_macros/src/macros/enum_iter.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/strum_macros/src/macros/enum_iter.rs b/strum_macros/src/macros/enum_iter.rs index 8497404..0a59deb 100644 --- a/strum_macros/src/macros/enum_iter.rs +++ b/strum_macros/src/macros/enum_iter.rs @@ -71,7 +71,9 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result { Ok(quote! { #[doc = #doc_comment] - #[derive(Clone, Copy, Eq, PartialEq)] + #[allow( + missing_copy_implementations, + )] #vis struct #iter_name #ty_generics { idx: usize, back_idx: usize, @@ -158,5 +160,15 @@ pub fn enum_iter_inner(ast: &DeriveInput) -> syn::Result { } impl #impl_generics ::core::iter::FusedIterator for #iter_name #ty_generics #where_clause { } + + impl #impl_generics Clone for #iter_name #ty_generics #where_clause { + fn clone(&self) -> #iter_name #ty_generics { + #iter_name { + idx: self.idx, + back_idx: self.back_idx, + marker: self.marker.clone(), + } + } + } }) }