Crates.io | rscel |
lib.rs | rscel |
version | |
source | src |
created_at | 2024-01-11 05:35:13.197321 |
updated_at | 2025-01-12 22:50:23.649423 |
description | Cel interpreter in rust |
homepage | |
repository | |
max_upload_size | |
id | 1095884 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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:
The basic example of how to use:
use rscel::{CelContext, BindContext};
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 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), 7.into());