13 releases (7 breaking)

0.10.1 Jul 23, 2025
0.8.1 Apr 29, 2025
0.8.0 Nov 4, 2024
0.7.1 Jul 29, 2024
0.1.3 Dec 20, 2020

#635 in Parser implementations

Download history 2048/week @ 2026-01-26 3024/week @ 2026-02-02 2898/week @ 2026-02-09 4254/week @ 2026-02-16 3287/week @ 2026-02-23 3540/week @ 2026-03-02 6912/week @ 2026-03-09 6556/week @ 2026-03-16 5493/week @ 2026-03-23 8150/week @ 2026-03-30 6213/week @ 2026-04-06 7208/week @ 2026-04-13 7806/week @ 2026-04-20 5997/week @ 2026-04-27 6364/week @ 2026-05-04 6993/week @ 2026-05-11

27,678 downloads per month
Used in 36 crates (3 directly)

MIT license

440KB
10K SLoC

Common Expression Language (Rust)

Rust

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))

Getting Started

Add cel to your Cargo.toml:

[dependencies]
cel = "0.13.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());
}

Examples

Check out these other examples to learn how to use this library:

  • Simple - A simple example of how to use the library.
  • Variables - Passing variables and using them in your program.
  • Functions - Defining and using custom functions in your program.
  • Concurrent Execution - Executing the same program concurrently.

Dependencies

~1.5MB
~32K SLoC