Function caldyn::eval
[−]
[src]
pub fn eval<'a, C>(input: &str, context: C) -> Result<f64, Error> where
C: Into<Option<&'a Context<'a>>>,
Evaluate a single expression from input
.
Returns Ok(result)
if the evaluation is successful, or Err(cause)
if
parsing or evaluating the expression failed.
Example
use caldyn::{eval, Context}; assert_eq!(eval("45 - 2^3", None), Ok(37.0)); let mut context = Context::new(); context.set("a", -5.0); assert_eq!(eval("3 * a", &context), Ok(-15.0));