eval_with_static_context

Function eval_with_static_context 

Source
pub fn eval_with_static_context(
    input: &str,
    context: &Context,
) -> EvalResult<Value>
Expand description

Evaluate an expression not allowing context changes.

See also eval andeval_with_mutable_context.

As in eval you cannot declare functions or variables using this function, but in this case the context can already have its own declarations and use your own settings.

ยงExamples

use num_parser::*;

// Create context with custom settings
let context = Context::new(
    settings::Rounding::Round(2),
    settings::AngleUnit::Turn,
    settings::DepthLimit::Limit(500)
);

let res = eval_with_static_context("pi + 1", &context).unwrap();

assert_eq!(res, Value::from(4.14));