Expand description
Activation context for expression evaluation.
This module provides the Activation
type, which serves as the runtime context
for CEL expression evaluation. Activations contain variable bindings and function
implementations that are used during expression evaluation.
§Key Concepts
§Activation Interface
The ActivationInterface
trait defines the contract for providing variable
and function bindings to the CEL evaluator. It provides access to:
- Variable bindings: Map variable names to runtime values
- Function bindings: Provide runtime function implementations
§Activation Types
The module provides several activation types:
Activation<'f>
: Standard activation for synchronous evaluationAsyncActivation<'f>
: Activation with async function support()
: Empty activation for expressions without variables/functions
§Variable Binding
Variables can be bound to values that match the types declared in the environment:
use cel_cxx::*;
let activation = Activation::new()
.bind_variable("user_name", "Alice".to_string())?
.bind_variable("user_age", 30i64)?
.bind_variable("is_admin", true)?;
§Function Binding
Functions can be bound at runtime to override or supplement environment functions:
use cel_cxx::*;
let activation = Activation::new()
.bind_global_function("custom_add", |a: i64, b: i64| a + b)?
.bind_member_function("to_upper", |s: String| s.to_uppercase())?;
§Variable Providers
For dynamic or computed values, you can bind variable providers:
use cel_cxx::*;
let activation = Activation::new()
.bind_variable_provider("current_time", || {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs() as i64
})?;
§Empty Activations
For expressions that don’t require any bindings, you can use the unit type:
use cel_cxx::*;
let env = Env::builder().build()?;
let program = env.compile("1 + 2 * 3")?;
let result = program.evaluate(())?; // No activation needed
§Async Support
When the async
feature is enabled, activations can contain async functions:
use cel_cxx::*;
let activation = AsyncActivation::new_async()
.bind_global_function("fetch_data", |url: String| async move {
// Simulate async work
format!("Data from {}", url)
})?;
Structs§
- Activation
- Activation context for CEL expression evaluation.
Traits§
- Activation
Interface - Interface for providing variable and function bindings during evaluation.
Type Aliases§
- Async
Activation async
- Activation with async support.