MCPcopy Index your code
hub / github.com/cel-rust/cel-rust

github.com/cel-rust/cel-rust @v0.14.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.14.0 ↗ · + Follow
1,289 symbols 2,801 edges 53 files 301 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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:

cargo add cel

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.

Extension points exported contracts — how you extend this code

CELParserContext (Interface)
Trait for monomorphized trait object that corresponds to the nodes of parse tree generated for CELParser [48 implementers]
cel/src/parser/gen/celparser.rs
AsKeyRef (Interface)
Trait for converting to a borrowed [`KeyRef`] for efficient lookups. [6 implementers]
cel/src/common/types/map.rs
VariableResolver (Interface)
VariableResolver implements a custom resolver for variables that is consulted before looking at variables added to the c [4 …
cel/src/context.rs
PrimaryContextAttrs (Interface)
(no doc) [8 implementers]
cel/src/parser/gen/celparser.rs
LiteralContextAttrs (Interface)
(no doc) [9 implementers]
cel/src/parser/gen/celparser.rs

Core symbols most depended-on inside this repo

clone
called by 284
cel/src/common/types/list.rs
push
called by 102
cel/src/parser/parser.rs
map
called by 95
cel/src/common/types/optional.rs
try_into
called by 93
cel/src/objects.rs
iter
called by 56
cel/src/common/types/map.rs
next_expr
called by 51
cel/src/parser/parser.rs
execute
called by 50
cel/src/lib.rs
parse
called by 44
cel/src/parser/parser.rs

Shape

Method 831
Function 233
Class 123
Interface 73
Enum 29

Languages

Rust100%

Modules by API surface

cel/src/parser/gen/celparser.rs254 symbols
cel/src/parser/gen/celvisitor.rs110 symbols
cel/src/objects.rs95 symbols
cel/src/parser/parser.rs82 symbols
cel/src/parser/gen/cellistener.rs73 symbols
cel/src/ser.rs62 symbols
cel/src/functions.rs54 symbols
cel/src/common/types/list.rs35 symbols
cel/src/common/types/map.rs34 symbols
cel/src/common/types/int.rs29 symbols
cel/src/common/types/timestamp.rs28 symbols
cel/src/common/types/uint.rs26 symbols

For agents

$ claude mcp add cel-rust \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact