cargo format

This commit is contained in:
Ben Weinstein-Raun 2023-06-02 19:00:42 -07:00 committed by ISibboI
parent d45cb7c420
commit 1646a070a9
2 changed files with 30 additions and 26 deletions

View File

@ -1,4 +1,4 @@
use crate::{Node, operator::Operator}; use crate::{operator::Operator, Node};
use std::slice::{Iter, IterMut}; use std::slice::{Iter, IterMut};
/// An iterator that traverses an operator tree in pre-order. /// An iterator that traverses an operator tree in pre-order.
@ -49,7 +49,7 @@ pub struct OperatorIterMut<'a> {
impl<'a> OperatorIterMut<'a> { impl<'a> OperatorIterMut<'a> {
fn new(node: &'a mut Node) -> Self { fn new(node: &'a mut Node) -> Self {
OperatorIterMut { OperatorIterMut {
stack: vec![node.children.iter_mut()] stack: vec![node.children.iter_mut()],
} }
} }
} }
@ -92,4 +92,3 @@ impl Node {
OperatorIterMut::new(self) OperatorIterMut::new(self)
} }
} }

View File

@ -98,12 +98,13 @@ impl Node {
/// assert_eq!(iter.next(), None); /// assert_eq!(iter.next(), None);
/// ``` /// ```
pub fn iter_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operator_mut().filter_map(|operator| match operator { self.iter_operator_mut()
Operator::VariableIdentifierWrite { identifier } .filter_map(|operator| match operator {
| Operator::VariableIdentifierRead { identifier } Operator::VariableIdentifierWrite { identifier }
| Operator::FunctionIdentifier { identifier } => Some(identifier), | Operator::VariableIdentifierRead { identifier }
_ => None | Operator::FunctionIdentifier { identifier } => Some(identifier),
}) _ => None,
})
} }
/// Returns an iterator over all variable identifiers in this expression. /// Returns an iterator over all variable identifiers in this expression.
@ -152,11 +153,12 @@ impl Node {
/// assert_eq!(iter.next(), None); /// assert_eq!(iter.next(), None);
/// ``` /// ```
pub fn iter_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operator_mut().filter_map(|operator| match operator { self.iter_operator_mut()
Operator::VariableIdentifierWrite { identifier } .filter_map(|operator| match operator {
| Operator::VariableIdentifierRead { identifier } => Some(identifier), Operator::VariableIdentifierWrite { identifier }
_ => None, | Operator::VariableIdentifierRead { identifier } => Some(identifier),
}) _ => None,
})
} }
/// Returns an iterator over all read variable identifiers in this expression. /// Returns an iterator over all read variable identifiers in this expression.
@ -205,10 +207,11 @@ impl Node {
/// assert_eq!(iter.next(), None); /// assert_eq!(iter.next(), None);
/// ``` /// ```
pub fn iter_read_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_read_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operator_mut().filter_map(|operator| match operator { self.iter_operator_mut()
Operator::VariableIdentifierRead { identifier } => Some(identifier), .filter_map(|operator| match operator {
_ => None, Operator::VariableIdentifierRead { identifier } => Some(identifier),
}) _ => None,
})
} }
/// Returns an iterator over all write variable identifiers in this expression. /// Returns an iterator over all write variable identifiers in this expression.
@ -255,10 +258,11 @@ impl Node {
/// assert_eq!(iter.next(), None); /// assert_eq!(iter.next(), None);
/// ``` /// ```
pub fn iter_write_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_write_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operator_mut().filter_map(|operator| match operator { self.iter_operator_mut()
Operator::VariableIdentifierWrite { identifier } => Some(identifier), .filter_map(|operator| match operator {
_ => None, Operator::VariableIdentifierWrite { identifier } => Some(identifier),
}) _ => None,
})
} }
/// Returns an iterator over all function identifiers in this expression. /// Returns an iterator over all function identifiers in this expression.
@ -305,10 +309,11 @@ impl Node {
/// assert_eq!(iter.next(), None); /// assert_eq!(iter.next(), None);
/// ``` /// ```
pub fn iter_function_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> { pub fn iter_function_variable_identifiers_mut(&mut self) -> impl Iterator<Item = &mut String> {
self.iter_operator_mut().filter_map(|operator| match operator { self.iter_operator_mut()
Operator::FunctionIdentifier { identifier } => Some(identifier), .filter_map(|operator| match operator {
_ => None, Operator::FunctionIdentifier { identifier } => Some(identifier),
}) _ => None,
})
} }
/// Evaluates the operator tree rooted at this node with the given context. /// Evaluates the operator tree rooted at this node with the given context.