Replace manual type_id with builtin function of trait Any

Relates to #44
This commit is contained in:
Sebastian Schmidt 2019-04-13 20:31:47 +02:00
parent d576cec9b9
commit 2e929ae0fe
2 changed files with 6 additions and 3 deletions

View File

@ -95,7 +95,7 @@ impl Operator {
// Make this a const fn once #57563 is resolved
fn is_flatten_chains(&self) -> bool {
match self {
Operator::Chain => true,
Operator::Tuple => true,
_ => false,
}
}
@ -112,7 +112,8 @@ impl Operator {
use crate::operator::Operator::*;
match self {
Add | Sub | Mul | Div | Mod | Exp | Eq | Neq | Gt | Lt | Geq | Leq | And | Or
| Tuple | Assign | Chain => Some(2),
| Assign | Chain => Some(2),
Tuple => None,
Not | Neg | RootNode => Some(1),
Const { value: _ } => Some(0),
VariableIdentifier { identifier: _ } => Some(0),

View File

@ -11,6 +11,8 @@ use crate::{
operator::*,
value::Value,
};
use std::error::Error;
use std::any::Any;
mod display;
mod iter;
@ -383,7 +385,7 @@ impl Node {
.last_mut()
.unwrap()
.insert_back_prioritized(node, false)
} else if self.children.last().unwrap().operator().id() == node.operator().id() && node.operator().is_flatten_chains() && !self.children.last().unwrap().has_enough_children() {
} else if self.children.last().unwrap().operator().type_id() == node.operator().type_id() && node.operator().is_flatten_chains() && !self.children.last().unwrap().has_enough_children() {
// The operators will be chained together, and the next value will be added to this nodes last child.
Ok(())
} else {