10 releases

0.3.0 Nov 7, 2024
0.2.2 Aug 25, 2022
0.2.1 Apr 26, 2022
0.1.7 Oct 16, 2020
0.1.6 Aug 17, 2020

#261 in Encoding

Download history 236/week @ 2024-08-21 924/week @ 2024-08-28 617/week @ 2024-09-04 426/week @ 2024-09-11 1793/week @ 2024-09-18 922/week @ 2024-09-25 688/week @ 2024-10-02 527/week @ 2024-10-09 694/week @ 2024-10-16 1657/week @ 2024-10-23 756/week @ 2024-10-30 1308/week @ 2024-11-06 861/week @ 2024-11-13 1083/week @ 2024-11-20 874/week @ 2024-11-27 811/week @ 2024-12-04

3,849 downloads per month

MPL-2.0 license

185KB
4.5K SLoC

A JEXL evaluator written in Rust This crate depends on a JEXL parser crate that handles all the parsing and is a part of the same workspace. JEXL is an expression language used by Mozilla, you can find more information here: https://github.com/mozilla/mozjexl

How to use

The access point for this crate is the eval functions of the Evaluator Struct You can use the eval function directly to evaluate standalone statements

For example:

use jexl_eval::Evaluator;
use serde_json::json as value;
let evaluator = Evaluator::new();
assert_eq!(evaluator.eval("'Hello ' + 'World'").unwrap(), value!("Hello World"));

You can also run the statements against a context using the eval_in_context function The context can be any type that implements the serde::Serializable trait and the function will return errors if the statement doesn't match the context

For example:

use jexl_eval::Evaluator;
use serde_json::json as value;
let context = value!({"a": {"b": 2.0}});
let evaluator = Evaluator::new();
assert_eq!(evaluator.eval_in_context("a.b", context).unwrap(), value!(2.0));

Dependencies

~3–5MB
~90K SLoC