rename iterators to indicate that they're iterating over operators rather than nodes

This commit is contained in:
Ben Weinstein-Raun 2023-06-02 18:59:56 -07:00 committed by ISibboI
parent 0d549b1c36
commit d45cb7c420

View File

@ -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<IterMut<'a, Node>>, stack: Vec<IterMut<'a, Node>>,
} }
impl<'a> NodeIterMut<'a> { impl<'a> OperatorIterMut<'a> {
fn new(node: &'a mut Node) -> Self { fn new(node: &'a mut Node) -> Self {
NodeIterMut { OperatorIterMut {
stack: vec![node.children.iter_mut()] stack: vec![node.children.iter_mut()]
} }
} }
} }
impl<'a> Iterator for NodeIterMut<'a> { impl<'a> Iterator for OperatorIterMut<'a> {
type Item = &'a mut Operator; type Item = &'a mut Operator;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -88,7 +89,7 @@ impl Node {
/// Returns a mutable iterator over all operators in this tree. /// Returns a mutable iterator over all operators in this tree.
pub fn iter_operator_mut(&mut self) -> impl Iterator<Item = &mut Operator> { pub fn iter_operator_mut(&mut self) -> impl Iterator<Item = &mut Operator> {
NodeIterMut::new(self) OperatorIterMut::new(self)
} }
} }