Make functions to access operator and children of a Node public.

This commit is contained in:
Sebastian Schmidt 2021-10-12 15:10:04 +03:00
parent e0d4ef24e5
commit d2f3d415df
2 changed files with 20 additions and 2 deletions

View File

@ -6,6 +6,8 @@
### Added
* Public immutable and mutable accessor functions to the operator and children of a Node.
### Removed
### Changed

View File

@ -378,14 +378,30 @@ impl Node {
self.eval_empty_with_context_mut(&mut HashMapContext::new())
}
fn children(&self) -> &[Node] {
/// Returns the children of this node as a slice.
pub fn children(&self) -> &[Node] {
&self.children
}
fn operator(&self) -> &Operator {
/// Returns the operator associated with this node.
pub fn operator(&self) -> &Operator {
&self.operator
}
/// Returns a mutable reference to the vector containing the children of this node.
///
/// WARNING: Writing to this might have unexpected results, as some operators require certain amounts and types of arguments.
pub fn children_mut(&mut self) -> &mut Vec<Node> {
&mut self.children
}
/// Returns a mutable reference to the operator associated with this node.
///
/// WARNING: Writing to this might have unexpected results, as some operators require different amounts and types of arguments.
pub fn operator_mut(&mut self) -> &mut Operator {
&mut self.operator
}
fn has_enough_children(&self) -> bool {
Some(self.children().len()) == self.operator().max_argument_amount()
}