cel_cxx/variable/mod.rs
1//! Variable declaration and binding utilities.
2//!
3//! The variable system supports both compile-time variable declarations and runtime
4//! variable bindings. Variables can be constants, runtime values, or dynamic providers
5//! that compute values on demand.
6//!
7//! # Key Components
8//!
9//! - [`VariableRegistry`]: Compile-time variable registry for declaring variable types and defining constants
10//! - [`VariableBindings`]: Runtime variable bindings for providing variable values during evaluation
11//! - **Dynamic providers**: Functions that compute variable values at runtime
12//!
13//! # Examples
14//!
15//! ```rust,no_run
16//! use cel_cxx::*;
17//!
18//! // Declare variables and create bindings
19//! let mut env = Env::builder()
20//! .declare_variable::<String>("user")?
21//! .declare_variable::<i64>("age")?
22//! .build()?;
23//!
24//! let mut activation = Activation::new()
25//! .bind_variable("user", "Alice".to_string())?
26//! .bind_variable("age", 30i64)?;
27//! # Ok::<(), cel_cxx::Error>(())
28//! ```
29//!
30//! # Detailed Documentation
31//!
32//! Variable management for CEL expressions.
33//!
34//! This module provides functionality for managing variables and their bindings
35//! in CEL expression evaluation contexts. Variables can be bound to values
36//! and accessed during expression evaluation.
37//!
38//! # Key Components
39//!
40//! - **Variable Registry**: Central registry for managing variable declarations and bindings
41//! - **Variable Bindings**: Runtime value bindings for variables during evaluation
42//! - **Type Safety**: Compile-time and runtime type checking for variable access
43//!
44//! # Variable Types
45//!
46//! Variables in CEL can hold any value type that implements the required traits:
47//! - **Primitive types**: `int`, `uint`, `double`, `bool`, `string`, `bytes`
48//! - **Complex types**: `list`, `map`, `struct`, `type`
49//! - **Custom types**: User-defined types via `#[derive(Opaque)]`
50//! - **Optional types**: Nullable values using `Optional<T>`
51//!
52//! # Examples
53//!
54//! ## Basic variable binding
55//!
56//! ```rust,no_run
57//! use cel_cxx::{VariableRegistry, VariableBindings, Value};
58//!
59//! // Create registry and declare variables
60//! let mut registry = VariableRegistry::new();
61//! registry.declare::<i64>("user_id")?;
62//! registry.declare::<String>("user_name")?;
63//!
64//! // Create bindings with actual values
65//! let mut bindings = VariableBindings::new();
66//! bindings.bind("user_id", 12345i64)?;
67//! bindings.bind("user_name", "Alice".to_string())?;
68//!
69//! // Variables are now available for CEL expression evaluation
70//! # Ok::<(), cel_cxx::Error>(())
71//! ```
72//!
73//! ## Working with custom types
74//!
75//! ```rust,no_run
76//! use cel_cxx::{VariableRegistry, VariableBindings, Opaque};
77//!
78//! #[derive(Opaque, Debug, Clone, PartialEq)]
79//! #[cel_cxx(display)]
80//! struct User {
81//! id: i64,
82//! name: String,
83//! }
84//!
85//! let mut registry = VariableRegistry::new();
86//! registry.declare::<User>("current_user")?;
87//!
88//! let mut bindings = VariableBindings::new();
89//! let user = User { id: 123, name: "Bob".to_string() };
90//! bindings.bind("current_user", user)?;
91//! # Ok::<(), cel_cxx::Error>(())
92//! ```
93//!
94//! ## Optional variables
95//!
96//! ```rust,no_run
97//! use cel_cxx::{VariableRegistry, VariableBindings, Optional};
98//!
99//! let mut registry = VariableRegistry::new();
100//! registry.declare::<Optional<String>>("optional_value")?;
101//!
102//! let mut bindings = VariableBindings::new();
103//! bindings.bind("optional_value", Optional::new("Hello"))?;
104//! # Ok::<(), cel_cxx::Error>(())
105//! ```
106
107mod registry;
108pub use registry::*;
109
110mod bindings;
111pub use bindings::*;