From 4897952330878861e06d2b795e83dd75f50a5e30 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 23 Oct 2023 18:18:01 -0400 Subject: [PATCH] Make creating AllAstNodeIter explicit. This is to remove the ambiguity between calling iter on the specific structs like Document and calling iter on an AstNode by having an explicitly-named function to create the iterator. --- src/iter/all_ast_node_iter.rs | 11 +++++------ src/parser/document.rs | 2 +- src/parser/in_buffer_settings.rs | 2 +- src/types/mod.rs | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/iter/all_ast_node_iter.rs b/src/iter/all_ast_node_iter.rs index e4e6c2cc..b97689ab 100644 --- a/src/iter/all_ast_node_iter.rs +++ b/src/iter/all_ast_node_iter.rs @@ -90,12 +90,11 @@ impl<'r, 's> Iterator for AllAstNodeIter<'r, 's> { } } -impl<'r, 's> IntoIterator for AstNode<'r, 's> { - type Item = AstNode<'r, 's>; - - type IntoIter = AllAstNodeIter<'r, 's>; - - fn into_iter(self) -> Self::IntoIter { +impl<'r, 's> AstNode<'r, 's> { + /// Iterate all AST nodes. + /// + /// This is different from the iter/into_iter functions which iterate a single level of the children. This iterates the entire tree including returning the root node itself. + pub fn iter_all_ast_nodes(self) -> AllAstNodeIter<'r, 's> { AllAstNodeIter { root: Some(self), queue: VecDeque::new(), diff --git a/src/parser/document.rs b/src/parser/document.rs index be995477..0f11d885 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -143,7 +143,7 @@ fn document_org_source<'b, 'g, 'r, 's>( { // If there are radio targets in this document then we need to parse the entire document again with the knowledge of the radio targets. let all_radio_targets: Vec<&Vec>> = Into::::into(&document) - .into_iter() + .iter_all_ast_nodes() .filter_map(|ast_node| { if let AstNode::RadioTarget(ast_node) = ast_node { Some(ast_node) diff --git a/src/parser/in_buffer_settings.rs b/src/parser/in_buffer_settings.rs index d8c1bf43..b247bd7c 100644 --- a/src/parser/in_buffer_settings.rs +++ b/src/parser/in_buffer_settings.rs @@ -157,7 +157,7 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn apply_post_parse_in_buffer_settings<'g, 's, 'sf>(document: &mut Document<'s>) { document.category = Into::::into(&*document) - .into_iter() + .iter_all_ast_nodes() .filter_map(|ast_node| { if let AstNode::Keyword(ast_node) = ast_node { if ast_node.key.eq_ignore_ascii_case("category") { diff --git a/src/types/mod.rs b/src/types/mod.rs index d42ce25c..334dd2fb 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -13,7 +13,7 @@ pub use affiliated_keyword::AffiliatedKeyword; pub use affiliated_keyword::AffiliatedKeywordValue; pub use affiliated_keyword::AffiliatedKeywords; pub use affiliated_keyword::GetAffiliatedKeywords; -pub(crate) use ast_node::AstNode; +pub use ast_node::AstNode; pub use document::Document; pub use document::DocumentElement; pub use document::Heading;