eval

Function eval 

Source
pub fn eval(input: &str) -> EvalResult<Value>
Expand description

Evaluate an expression with the default context.

See also: eval_with_static_context and eval_with_mutable_context.

You cannot declare functions or variables using this function.

§Examples

This works:

use num_parser::*;

let result = eval("2 + 2").unwrap();

assert_eq!(result, Value::from(4));

This panics:

use num_parser::*;

// Unwraps an error.
let result = eval("f(x) = 2x").unwrap();