From d45cb7c42018e5b44bccc14459af842403332fcd Mon Sep 17 00:00:00 2001 From: Ben Weinstein-Raun Date: Fri, 2 Jun 2023 18:59:56 -0700 Subject: [PATCH] rename iterators to indicate that they're iterating over operators rather than nodes --- src/tree/iter.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tree/iter.rs b/src/tree/iter.rs index 931f42e..abae1ad 100644 --- a/src/tree/iter.rs +++ b/src/tree/iter.rs @@ -41,19 +41,20 @@ impl<'a> Iterator for NodeIter<'a> { } } -pub struct NodeIterMut<'a> { +/// An iterator that mutably traverses an operator tree in pre-order. +pub struct OperatorIterMut<'a> { stack: Vec>, } -impl<'a> NodeIterMut<'a> { +impl<'a> OperatorIterMut<'a> { fn new(node: &'a mut Node) -> Self { - NodeIterMut { + OperatorIterMut { stack: vec![node.children.iter_mut()] } } } -impl<'a> Iterator for NodeIterMut<'a> { +impl<'a> Iterator for OperatorIterMut<'a> { type Item = &'a mut Operator; fn next(&mut self) -> Option { @@ -88,7 +89,7 @@ impl Node { /// Returns a mutable iterator over all operators in this tree. pub fn iter_operator_mut(&mut self) -> impl Iterator { - NodeIterMut::new(self) + OperatorIterMut::new(self) } }