diff --git a/src/parser/list.rs b/src/parser/list.rs index f65609f2..e15e8da2 100644 --- a/src/parser/list.rs +++ b/src/parser/list.rs @@ -74,20 +74,19 @@ impl List { } } -pub struct NodeIter { - position: Option>>, +pub struct NodeIter<'a, T> { + position: &'a Option>>, } -impl Iterator for NodeIter { - // TODO: This would be a lot better if it returned borrows instead of clones of Rc - type Item = Rc>; +impl<'a, T> Iterator for NodeIter<'a, T> { + type Item = &'a 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(); + let next_position = &rc_node.parent; + let return_value = rc_node; (return_value, next_position) } };