From 857942e411d71d3c0787e14e220c8c7d9d491051 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 11 Aug 2024 08:48:53 -0700 Subject: [PATCH] Revert "Define Fields::members iterator type privately inside method" This reverts commit e8a9292cbd9f81b63479e15b0b59db644243500c. --- src/data.rs | 74 ++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/data.rs b/src/data.rs index 7f8a121c76..000ea0db2c 100644 --- a/src/data.rs +++ b/src/data.rs @@ -138,43 +138,6 @@ impl Fields { /// self.a.clone() }`. For structs with unnamed fields, `Self { 0: /// self.0.clone() }`. And for unit structs, `Self {}`. pub fn members(&self) -> impl Iterator + Clone + '_ { - struct Members<'a> { - fields: punctuated::Iter<'a, Field>, - index: u32, - } - - impl<'a> Iterator for Members<'a> { - type Item = Member; - - fn next(&mut self) -> Option { - let field = self.fields.next()?; - let member = match &field.ident { - Some(ident) => Member::Named(ident.clone()), - None => { - #[cfg(all(feature = "parsing", feature = "printing"))] - let span = crate::spanned::Spanned::span(&field.ty); - #[cfg(not(all(feature = "parsing", feature = "printing")))] - let span = proc_macro2::Span::call_site(); - Member::Unnamed(Index { - index: self.index, - span, - }) - } - }; - self.index += 1; - Some(member) - } - } - - impl<'a> Clone for Members<'a> { - fn clone(&self) -> Self { - Members { - fields: self.fields.clone(), - index: self.index, - } - } - } - Members { fields: self.iter(), index: 0, @@ -234,6 +197,43 @@ ast_struct! { } } +pub struct Members<'a> { + fields: punctuated::Iter<'a, Field>, + index: u32, +} + +impl<'a> Iterator for Members<'a> { + type Item = Member; + + fn next(&mut self) -> Option { + let field = self.fields.next()?; + let member = match &field.ident { + Some(ident) => Member::Named(ident.clone()), + None => { + #[cfg(all(feature = "parsing", feature = "printing"))] + let span = crate::spanned::Spanned::span(&field.ty); + #[cfg(not(all(feature = "parsing", feature = "printing")))] + let span = proc_macro2::Span::call_site(); + Member::Unnamed(Index { + index: self.index, + span, + }) + } + }; + self.index += 1; + Some(member) + } +} + +impl<'a> Clone for Members<'a> { + fn clone(&self) -> Self { + Members { + fields: self.fields.clone(), + index: self.index, + } + } +} + #[cfg(feature = "parsing")] pub(crate) mod parsing { use crate::attr::Attribute;