pub struct VariableRegistry { /* private fields */ }Expand description
Compile-time variable registry.
VariableRegistry manages variable declarations and constant definitions during the CEL environment
compilation phase. It maintains a mapping from variable names to variable entries, where each entry
can be either:
- A constant value (
Constant): A fixed value known at compile time - A variable declaration: A type declaration with value provided at runtime
§Examples
use cel_cxx::{ValueType, VariableRegistry};
let mut registry = VariableRegistry::new();
// Define constants
registry.define_constant("PI", 3.14159)?;
registry.define_constant("APP_NAME", "MyApp")?;
// Declare variables
registry.declare::<String>("user_input")?;
assert_eq!(registry.len(), 3);Implementations§
Source§impl VariableRegistry
impl VariableRegistry
Sourcepub fn define_constant<T>(
&mut self,
name: impl Into<String>,
value: T,
) -> Result<&mut Self, Error>where
T: IntoConstant,
pub fn define_constant<T>(
&mut self,
name: impl Into<String>,
value: T,
) -> Result<&mut Self, Error>where
T: IntoConstant,
Defines a constant value.
Constants are values that are known at compile time and don’t change during evaluation. They can be used directly in CEL expressions without requiring runtime bindings.
§Type Parameters
T: The constant type, must implementIntoConstant
§Parameters
name: The constant namevalue: The constant value
§Returns
Returns &mut Self to support method chaining, or Error if an error occurs
§Examples
use cel_cxx::VariableRegistry;
let mut registry = VariableRegistry::new();
registry
.define_constant("PI", 3.14159)?
.define_constant("APP_NAME", "MyApp")?
.define_constant("MAX_USERS", 1000i64)?;Sourcepub fn declare<T>(
&mut self,
name: impl Into<String>,
) -> Result<&mut Self, Error>where
T: TypedValue,
pub fn declare<T>(
&mut self,
name: impl Into<String>,
) -> Result<&mut Self, Error>where
T: TypedValue,
Declares a variable with a specific type.
Variable declarations only specify the type, with actual values provided at runtime
through Activation. The type is determined by the generic parameter T which
must implement TypedValue.
§Type Parameters
T: The variable type, must implementTypedValue
§Parameters
name: The variable name
§Returns
Returns &mut Self to support method chaining, or Error if an error occurs
§Examples
use cel_cxx::VariableRegistry;
let mut registry = VariableRegistry::new();
registry
.declare::<String>("user_name")?
.declare::<i64>("user_id")?
.declare::<bool>("is_admin")?;Sourcepub fn entries(
&self,
) -> impl Iterator<Item = (&String, &VariableDeclOrConstant)>
pub fn entries( &self, ) -> impl Iterator<Item = (&String, &VariableDeclOrConstant)>
Returns an iterator over all variable entries.
The iterator yields (name, entry) pairs for all registered variables and constants.
§Returns
Iterator yielding (&String, &VariableDeclOrConstant) pairs
Sourcepub fn entries_mut(
&mut self,
) -> impl Iterator<Item = (&String, &mut VariableDeclOrConstant)>
pub fn entries_mut( &mut self, ) -> impl Iterator<Item = (&String, &mut VariableDeclOrConstant)>
Returns a mutable iterator over all variable entries.
The iterator yields (name, entry) pairs and allows modifying the entries.
§Returns
Iterator yielding (&String, &mut VariableDeclOrConstant) pairs
Sourcepub fn find(&self, name: &str) -> Option<&VariableDeclOrConstant>
pub fn find(&self, name: &str) -> Option<&VariableDeclOrConstant>
Sourcepub fn find_mut(&mut self, name: &str) -> Option<&mut VariableDeclOrConstant>
pub fn find_mut(&mut self, name: &str) -> Option<&mut VariableDeclOrConstant>
Sourcepub fn remove(&mut self, name: &str) -> Option<VariableDeclOrConstant>
pub fn remove(&mut self, name: &str) -> Option<VariableDeclOrConstant>
Trait Implementations§
Source§impl Debug for VariableRegistry
impl Debug for VariableRegistry
Source§impl Default for VariableRegistry
impl Default for VariableRegistry
Source§fn default() -> VariableRegistry
fn default() -> VariableRegistry
Auto Trait Implementations§
impl Freeze for VariableRegistry
impl RefUnwindSafe for VariableRegistry
impl Send for VariableRegistry
impl Sync for VariableRegistry
impl Unpin for VariableRegistry
impl UnwindSafe for VariableRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more