Function evalexpr::build_operator_tree [−][src]
pub fn build_operator_tree(string: &str) -> EvalexprResult<Node>
Expand description
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 contexts.
Examples
use evalexpr::*; let precomputed = build_operator_tree("one + two + three").unwrap(); // Do proper error handling here let mut context = HashMapContext::new(); context.set_value("one".into(), 1.into()).unwrap(); // Do proper error handling here context.set_value("two".into(), 2.into()).unwrap(); // Do proper error handling here context.set_value("three".into(), 3.into()).unwrap(); // Do proper error handling here assert_eq!(precomputed.eval_with_context(&context), Ok(Value::from(6))); context.set_value("three".into(), 5.into()).unwrap(); // Do proper error handling here assert_eq!(precomputed.eval_with_context(&context), Ok(Value::from(8)));
See the crate doc for more examples and explanations of the expression format.