()
| 5 | use std::sync::Arc; |
| 6 | |
| 7 | fn 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 |
nothing calls this directly
no test coverage detected