From cfdcb7408a0b62d7a91b5a2339963e380b1c74da Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 11 Dec 2022 01:04:51 -0500 Subject: [PATCH] Implement iterator with far too many clones. --- src/parser/list.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/parser/list.rs b/src/parser/list.rs index bd891b1..f65609f 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -73,3 +73,25 @@ impl List { } } } + +pub struct NodeIter { + position: Option>>, +} + +impl Iterator for NodeIter { + // TODO: This would be a lot better if it returned borrows instead of clones of Rc + type Item = Rc>; + + fn next(&mut self) -> Option { + let (return_value, next_position) = match &self.position { + None => return None, + Some(rc_node) => { + let next_position = rc_node.parent.clone(); + let return_value = rc_node.clone(); + (return_value, next_position) + } + }; + self.position = next_position; + Some(return_value) + } +}