rscel 0.8.0

Cel interpreter in rust
Documentation

rscel

RsCel is a CEL evaluator written in Rust. CEL is a google project that describes a turing-incomplete language that can be used to evaluate a user provdided expression. The language specification can be found here.

The design goals of this project were are as follows:

  • Flexible enough to allow for a user to bend the spec if needed
  • Sandbox'ed in such a way that only specific values can be bound
  • Can be used as a wasm depenedency (or other ffi)

While Google's CEL spec was designed around the protobuf message, I decided to focus on using the JSON message instead (CEL spec specifies how to convert from JSON to CEL types).

The basic example of how to use:

use rscel::{CelContext, BindContext, serde_json};

let mut ctx = CelContext::new();
let mut exec_ctx = BindContext::new();

ctx.add_program_str("main", "foo + 3").unwrap();
exec_ctx.bind_param("foo", 3.into()); // convert to serde_json::Value

let res = ctx.exec("main", &exec_ctx).unwrap(); // ValueCell::Int(6)
assert!(TryInto::<i64>::try_into(res).unwrap() == 6);

Current Benchmark Times

Bench Run Time
Run One No Binding: 0.000310S
Run Many No Binding: 0.003657S
Run One With Binding: 0.000033S
Run Many With Bindings: 0.004281S
Build Many: 0.002312S
Build Many With Bindings: 0.051369S

Build status: Rust