From 531b7b72a0b50e96a65b4b9206b4f239f4339647 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Sat, 13 Apr 2019 19:11:09 +0200 Subject: [PATCH] Make `Operator::max_argument_amount` optional Relates to #44 --- src/operator/mod.rs | 14 +++++++------- src/tree/mod.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/operator/mod.rs b/src/operator/mod.rs index a86eb53..a94dc9c 100644 --- a/src/operator/mod.rs +++ b/src/operator/mod.rs @@ -94,20 +94,20 @@ impl Operator { /// True if this operator is a leaf, meaning it accepts no arguments. // Make this a const fn once #57563 is resolved pub(crate) fn is_leaf(&self) -> bool { - self.max_argument_amount() == 0 + self.max_argument_amount() == Some(0) } /// Returns the maximum amount of arguments required by this operator. // Make this a const fn once #57563 is resolved - pub(crate) fn max_argument_amount(&self) -> usize { + pub(crate) fn max_argument_amount(&self) -> Option { use crate::operator::Operator::*; match self { Add | Sub | Mul | Div | Mod | Exp | Eq | Neq | Gt | Lt | Geq | Leq | And | Or - | Tuple | Assign | Chain => 2, - Not | Neg | RootNode => 1, - Const { value: _ } => 0, - VariableIdentifier { identifier: _ } => 0, - FunctionIdentifier { identifier: _ } => 1, + | Tuple | Assign | Chain => Some(2), + Not | Neg | RootNode => Some(1), + Const { value: _ } => Some(0), + VariableIdentifier { identifier: _ } => Some(0), + FunctionIdentifier { identifier: _ } => Some(1), } } diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 0d728d2..7e9f8b8 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -362,7 +362,7 @@ impl Node { } fn has_enough_children(&self) -> bool { - self.children().len() == self.operator().max_argument_amount() + Some(self.children().len()) == self.operator().max_argument_amount() } fn insert_back_prioritized(&mut self, node: Node, is_root_node: bool) -> EvalexprResult<()> {