V_eval 0.0.1: Evaluate with context

#1

Implemented with syn and quote. You can manage a context, evaluate expressions from a string and enter them in the runtime.

The example:

use v_eval::{Value, Eval};

fn main() -> Result<(), ()> {
    let e = Eval::default()
        .insert("foo", "true")?
        .insert("bar", "false")?;

    assert_eq!(e.eval("foo != bar").unwrap(), Value::Bool(true));
    assert_eq!(
        e.eval("true && foo != bar && true").unwrap(),
        Value::Bool(true)
    );
    assert_eq!(e.eval("1 == 1 != bar").unwrap(), Value::Bool(true));
    assert_eq!(e.eval("1 == 1 + 1 == bar").unwrap(), Value::Bool(true));
    
    Ok(())
}

I hope it helps.

https://crates.io/crates/v_eval

2 Likes

#2

I am currently using the eval crate. Is there a reason for me to switch?

0 Likes

#3

The specific purpose of this crate is to evaluate in derivation, your main mission is to be within crate yarte.

If you have to solve similar problems has a template engine this is your crate.

I can not talk about speed because there are no benchmarks, but I invite you to put it to the test.
That does not mean that it will not grow, but that it is still very young.

0 Likes

#4

We have launched another crate dedicated only to mathematical expressions.
It uses the same SYA but the wrapper of the values has been removed for greater performance.
It has support for f32 and f64 selectable by the "double" feature. In the next version the trigonometric functions will be added in a few days.

I hope it is what you seek.

https://crates.io/crates/mathew

0 Likes