From d2f3d415dfb0760f2f919e858cf3875b9e89e08e Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 12 Oct 2021 15:10:04 +0300 Subject: [PATCH] Make functions to access operator and children of a Node public. --- CHANGELOG.md | 2 ++ src/tree/mod.rs | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b37f94..549a178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Added + * Public immutable and mutable accessor functions to the operator and children of a Node. + ### Removed ### Changed diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 3dff3b6..d173ad5 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -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 { + &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() }