[][src]Function evalexpr::build_operator_tree

pub fn build_operator_tree(string: &str) -> Result<Node, Error>

Build the operator tree for the given expression string.

The operator tree can later on be evaluated directly. This saves runtime if a single expression should be evaluated multiple times, for example with differing configurations.

Examples

use evalexpr::*;

let precomputed = build_operator_tree("one + two + three").unwrap();

let mut configuration = HashMapConfiguration::new();
configuration.insert_variable("one", 1);
configuration.insert_variable("two", 2);
configuration.insert_variable("three", 3);

assert_eq!(precomputed.eval_with_configuration(&configuration), Ok(Value::from(6)));

configuration.insert_variable("three", 5);
assert_eq!(precomputed.eval_with_configuration(&configuration), Ok(Value::from(8)));

See the crate doc for more examples and explanations of the expression format.