From 5d1582be4d33f9eff6e718d1b6b68c2889b9725b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 29 Sep 2023 20:38:04 -0400 Subject: [PATCH] Remove multi_field_getter_iter. This was written because I originally intended to make the fields of the ast node types entirely private, but that made constructing them tedious so they are pub(crate) which coincidentally also allows them to be used by the iterator. --- src/iter/ast_node_iter.rs | 7 +++---- src/iter/macros.rs | 40 --------------------------------------- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/iter/ast_node_iter.rs b/src/iter/ast_node_iter.rs index 89d35a8..6c51c11 100644 --- a/src/iter/ast_node_iter.rs +++ b/src/iter/ast_node_iter.rs @@ -3,7 +3,6 @@ use std::marker::PhantomData; use super::ast_node::AstNode; use super::macros::children_iter; use super::macros::empty_iter; -use super::macros::multi_field_getter_iter; use super::macros::multi_field_iter; use crate::types::AngleLink; use crate::types::BabelCall; @@ -224,12 +223,12 @@ children_iter!( PlainListIter, std::slice::Iter<'r, PlainListItem<'s>> ); -multi_field_getter_iter!( +multi_field_iter!( PlainListItem<'s>, PlainListItemIter, - get_tag, + tag, std::slice::Iter<'r, Object<'s>>, - get_children, + children, std::slice::Iter<'r, Element<'s>> ); children_iter!( diff --git a/src/iter/macros.rs b/src/iter/macros.rs index 466a011..3834d1b 100644 --- a/src/iter/macros.rs +++ b/src/iter/macros.rs @@ -112,43 +112,3 @@ $fieldname: self.$fieldname.iter(), } pub(crate) use multi_field_iter; - -/// Create iterators for ast nodes using getters where it has to iterate over multiple child lists. -macro_rules! multi_field_getter_iter { - ($astnodetype:ty, $itertype:ident, $firstfieldname: ident, $firstinnertype:ty, $($fieldname: ident, $innertype:ty),*) => { - pub struct $itertype<'r, 's> { - $firstfieldname: $firstinnertype, - $( -$fieldname: $innertype, -),* - } - - impl<'r, 's> Iterator for $itertype<'r, 's> { - type Item = AstNode<'r, 's>; - - fn next(&mut self) -> Option { - self.$firstfieldname.next().map(Into::::into) - $( -.or_else(|| self.$fieldname.next().map(Into::::into)) -),* - } - } - - impl<'r, 's> IntoIterator for &'r $astnodetype { - type Item = AstNode<'r, 's>; - - type IntoIter = $itertype<'r, 's>; - - fn into_iter(self) -> Self::IntoIter { - $itertype { - $firstfieldname: self.$firstfieldname().iter(), - $( -$fieldname: self.$fieldname().iter(), -),* - } - } - } - }; -} - -pub(crate) use multi_field_getter_iter;