Skip to content

Commit

Permalink
Make functions to access operator and children of a Node public.
Browse files Browse the repository at this point in the history
  • Loading branch information
ISibboI committed Oct 12, 2021
1 parent e0d4ef2 commit d2f3d41
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Added

* Public immutable and mutable accessor functions to the operator and children of a Node.

### Removed

### Changed
Expand Down
20 changes: 18 additions & 2 deletions src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit d2f3d41

Please sign in to comment.