5 releases (1 stable)

new 1.0.0 Apr 22, 2024
0.11.2 Apr 17, 2024
0.9.0 Feb 16, 2024
0.8.0 Jan 20, 2024
0.7.2 Jan 11, 2024

#408 in WebAssembly

Download history 4/week @ 2024-01-10 7/week @ 2024-01-17 131/week @ 2024-02-14 37/week @ 2024-02-21 49/week @ 2024-02-28 23/week @ 2024-03-06 28/week @ 2024-03-13 5/week @ 2024-03-27 11/week @ 2024-04-03 258/week @ 2024-04-17

274 downloads per month

MIT license

235KB
6K SLoC

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)

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()); // 3 converted to CelValue

let res = ctx.exec("main", &exec_ctx).unwrap(); // CelValue::Int(6)
assert_eq!(res, 6.into());

As of 0.10.0 binding protobuf messages from the protobuf crate is now available! Given the following protobuf message:


message Point {
  int32 x = 1;
  int32 y = 2;
}
  

The following code can be used to evaluate a CEL expression on a Point message:

use rscel::{CelContext, BindContext};

// currently rscel required protobuf messages to be in a box
let p = Box::new(protos::Point::new());
p.x = 4;
p.y = 5;

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

ctx.add_program_str("main", "p.x + 3").unwrap();
exec_ctx.bind_protobuf_msg("p", p);

assert_eq!(ctx.exec("main", &exec_ctx).unwrap(), 7.into());
  

Dependencies

~8–13MB
~208K SLoC