6 releases

0.1.7 Oct 16, 2020
0.1.6 Aug 17, 2020
Download history 8/week @ 2020-08-04 54/week @ 2020-08-11 36/week @ 2020-08-18 12/week @ 2020-08-25 12/week @ 2020-09-01 19/week @ 2020-09-08 5/week @ 2020-09-15 13/week @ 2020-09-22 48/week @ 2020-09-29 38/week @ 2020-10-06 25/week @ 2020-10-13 30/week @ 2020-10-20 39/week @ 2020-10-27 303/week @ 2020-11-03 459/week @ 2020-11-10 168/week @ 2020-11-17

83 downloads per month

MPL-2.0 license

165KB
4.5K SLoC

jexl-rs CircleCI

JEXL in Rust


lib.rs:

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

~2–3MB
~79K SLoC