| Crates.io | cel |
| lib.rs | cel |
| version | 0.11.2 |
| created_at | 2020-01-09 20:24:37.429022+00 |
| updated_at | 2025-09-19 18:05:31.260978+00 |
| description | A parser and interpreter for the Common Expression Language (CEL) |
| homepage | |
| repository | https://github.com/cel-rust/cel-rust |
| max_upload_size | |
| id | 196980 |
| size | 683,764 |
The Common Expression Language (CEL) is a non-Turing complete language designed for simplicity, speed, safety, and portability. CEL's C-like syntax looks nearly identical to equivalent expressions in C++, Go, Java, and TypeScript. CEL is ideal for lightweight expression evaluation when a fully sandboxed scripting language is too resource intensive.
// Check whether a resource name starts with a group name.
resource.name.startsWith("/groups/" + auth.claims.group)
// Determine whether the request is in the permitted time window.
request.time - resource.age < duration("24h")
// Check whether all resource names in a list match a given filter.
auth.claims.email_verified && resources.all(r, r.startsWith(auth.claims.email))
Add cel to your Cargo.toml:
[dependencies]
cel = "0.11.0"
Create and execute a simple CEL expression:
use cel::{Context, Program};
fn main() {
let program = Program::compile("add(2, 3) == 5").unwrap();
let mut context = Context::default();
context.add_function("add", |a: i64, b: i64| a + b);
let value = program.execute(&context).unwrap();
assert_eq!(value, true.into());
}
Check out these other examples to learn how to use this library: