Available on crate feature
expression only.Expand description
Core CEL expression operations – compile, evaluate, validate.
Wraps the cel crate (renamed from cel-interpreter), enforcing the
DFE expression profile on every compilation path. Both Python (via
common-expression-language PyO3 bindings) and Rust share the same
Rust crate – zero behavioural drift between services.
§Profile Configuration
When the config feature is enabled alongside expression, the profile
is loaded automatically from the config cascade under the expression
key. Applications can set overrides in their settings.yaml:
expression:
allow_regex: true
allow_iteration: false
allow_time: falseWithout the config feature (or before config::setup() is called),
ProfileConfig::default() is used – all restrictions active.
§Usage
use hyperi_rustlib::expression::{compile, evaluate, evaluate_condition, validate};
use std::collections::HashMap;
use serde_json::json;
// Validate before storing (UI pre-submit)
assert!(validate(r#"severity == "critical""#).is_empty());
// One-shot evaluation
let mut data = HashMap::new();
data.insert("severity".into(), json!("critical"));
let result = evaluate(r#"severity == "critical""#, &data).unwrap();
assert_eq!(result, true.into());
// Boolean condition (missing fields → false)
let empty = HashMap::new();
assert!(!evaluate_condition(r#"severity == "critical""#, &empty));
// Compile once, evaluate many (hot path)
let program = compile("amount > threshold").unwrap();
// ... call program.execute(&context) per recordFunctions§
- build_
context - Build a CEL
Contextfrom any iterable of(key, value)pairs. - compile
- Compile a CEL expression, enforcing the DFE profile.
- compile_
with_ config - Compile a CEL expression with an explicit profile config.
- evaluate
- Compile and evaluate a CEL expression in one step.
- evaluate_
condition - Evaluate a boolean condition, returning
falseon missing fields. - validate
- Validate an expression for syntax and DFE profile compliance.
- validate_
with_ config - Validate an expression with an explicit profile config.