From 9103aa7a266a56f0b628baa7d32aee5d723acf6d Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 13 Jul 2021 13:55:22 +0300 Subject: [PATCH] Make more functions const. --- src/operator/mod.rs | 14 +++++--------- src/token/mod.rs | 8 +++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/operator/mod.rs b/src/operator/mod.rs index 0ae3794..3ebf4a1 100644 --- a/src/operator/mod.rs +++ b/src/operator/mod.rs @@ -102,8 +102,7 @@ impl Operator { /// Returns the precedence of the operator. /// A high precedence means that the operator has priority to be deeper in the tree. - // Make this a const fn once #57563 is resolved - pub(crate) fn precedence(&self) -> i32 { + pub(crate) const fn precedence(&self) -> i32 { use crate::operator::Operator::*; match self { RootNode => 200, @@ -133,28 +132,25 @@ impl Operator { /// Returns true if chains of operators with the same precedence as this one should be evaluated left-to-right, /// and false if they should be evaluated right-to-left. /// Left-to-right chaining has priority if operators with different order but same precedence are chained. - // Make this a const fn once #57563 is resolved - pub(crate) fn is_left_to_right(&self) -> bool { + pub(crate) const fn is_left_to_right(&self) -> bool { use crate::operator::Operator::*; !matches!(self, Assign | FunctionIdentifier { identifier: _ }) } /// Returns true if chains of this operator should be flattened into one operator with many arguments. - // Make this a const fn once #57563 is resolved - pub(crate) fn is_sequence(&self) -> bool { + pub(crate) const fn is_sequence(&self) -> bool { use crate::operator::Operator::*; matches!(self, Tuple | Chain) } /// True if this operator is a leaf, meaning it accepts no arguments. - // Make this a const fn once #57563 is resolved + // Make this a const fn as soon as whatever is missing gets stable (issue #57563) pub(crate) fn is_leaf(&self) -> bool { 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) -> Option { + pub(crate) const 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 diff --git a/src/token/mod.rs b/src/token/mod.rs index 56b05f1..0ae8c85 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -88,7 +88,7 @@ pub enum PartialToken { VerticalBar, } -// Make this a const fn as soon as match gets stable (issue #57563) +// Make this a const fn as soon as is_whitespace and to_string get stable (issue #57563) fn char_to_partial_token(c: char) -> PartialToken { match c { '+' => PartialToken::Plus, @@ -122,8 +122,7 @@ fn char_to_partial_token(c: char) -> PartialToken { } impl Token { - // Make this a const fn as soon as match gets stable (issue #57563) - pub(crate) fn is_leftsided_value(&self) -> bool { + pub(crate) const fn is_leftsided_value(&self) -> bool { match self { Token::Plus => false, Token::Minus => false, @@ -166,8 +165,7 @@ impl Token { } } - // Make this a const fn as soon as match gets stable (issue #57563) - pub(crate) fn is_rightsided_value(&self) -> bool { + pub(crate) const fn is_rightsided_value(&self) -> bool { match self { Token::Plus => false, Token::Minus => false,