MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / main

Function main

example/src/functions.rs:7–26  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5use std::sync::Arc;
6
7fn main() {
8 let program = Program::compile("add(2, 3) == 5 && ''.isEmpty() && fail()").unwrap();
9 let mut context = Context::default();
10
11 // Add functions using closures
12 context.add_function("add", |a: i64, b: i64| a + b);
13
14 // Add methods to a string type
15 context.add_function("isEmpty", is_empty);
16
17 // Use the function context to return error messages
18 context.add_function("fail", fail);
19
20 // See all the different value types you can accept in your functions
21 context.add_function("primitives", primitives);
22
23 // Run the program
24 let result = program.execute(&context);
25 assert!(matches!(result, Err(ExecutionError::FunctionError { .. })));
26}
27
28/// A method on a string type. When added to the CEL context, this function
29/// can be called by running. We use the [`This`] extractor give us a reference

Callers

nothing calls this directly

Calls 2

add_functionMethod · 0.80
executeMethod · 0.80

Tested by

no test coverage detected