Function evalexpr::eval_with_context
source · [−]pub fn eval_with_context<C: Context>(
string: &str,
context: &C
) -> EvalexprResult<Value>
Expand description
Evaluate the given expression string with the given context.
Examples
use evalexpr::*;
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!(eval_with_context("one + two + three", &context), Ok(Value::from(6)));
See the crate doc for more examples and explanations of the expression format.