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) + } +}