pub struct Expr { /* fields omitted */ }
A parsed and optimized mathematical expression.
let expr = Expr::parse("3 + 5 * 2").unwrap();
assert_eq!(expr.eval(None), Ok(13.0));
let mut context = Context::new();
context.set("a", 42.0);
let expr = Expr::parse("-2 * a").unwrap();
assert_eq!(expr.eval(&context), Ok(-84.0));
Parse the given mathematical expression
into an Expr
.
assert!(Expr::parse("3 + 5 * 2").is_ok());
assert!(Expr::parse("3eff + 5 * 2").is_err());
Evaluate the expression in a given optional context
.
let expr = Expr::parse("3 + 5 * 2").unwrap();
assert_eq!(expr.eval(None), Ok(13.0));
let expr = Expr::parse("3 + a").unwrap();
let mut context = Context::new();
context.set("a", -5.0);
assert_eq!(expr.eval(&context), Ok(-2.0));
context.set("a", 2.0);
assert_eq!(expr.eval(&context), Ok(5.0));
Formats the value using the given formatter. Read more
Performs copy-assignment from source
. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.