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