Expand description
CEL type system types and type definitions.
This module provides the core type system for CEL expressions, including
the ValueType
enum and type conversion utilities.
This module provides the complete type system for CEL (Common Expression Language). It defines all the types that can be used in CEL expressions, from primitive types like integers and strings to complex types like lists, maps, and Protocol Buffer messages.
§Type Hierarchy
The CEL type system is built around the ValueType
enum, which represents all
possible types in CEL:
§Primitive Types
null
: Represents the absence of a valuebool
: Boolean values (true
/false
)int
: 64-bit signed integersuint
: 64-bit unsigned integersdouble
: Double-precision floating point numbersstring
: UTF-8 encoded textbytes
: Byte arrays
§Time Types
duration
: Time spans (from Protocol Buffers)timestamp
: Points in time (from Protocol Buffers)
§Collection Types
list<T>
: Ordered sequences of valuesmap<K, V>
: Key-value mappings
§Protocol Buffer Types
struct
: Protocol Buffer messages- Wrapper types:
BoolValue
,StringValue
, etc. any
: Can hold any Protocol Buffer messageenum
: Protocol Buffer enumerations
§Advanced Types
type
: Represents types themselves as valuesfunction
: Function signaturesoptional<T>
: Nullable values- Opaque types: Custom user-defined types
- Type parameters: For generic type definitions
§Examples
§Working with primitive types
use cel_cxx::types::*;
use cel_cxx::Kind;
// Create primitive types
let int_type = ValueType::Int;
let string_type = ValueType::String;
let bool_type = ValueType::Bool;
// Check type kinds
assert_eq!(int_type.kind(), Kind::Int);
assert_eq!(string_type.kind(), Kind::String);
assert_eq!(bool_type.kind(), Kind::Bool);
§Working with collection types
use cel_cxx::types::*;
// List of strings: list<string>
let string_list = ValueType::List(ListType::new(ValueType::String));
// Map from string to int: map<string, int>
let string_to_int_map = ValueType::Map(MapType::new(
MapKeyType::String,
ValueType::Int
));
// Nested types: list<map<string, int>>
let nested_type = ValueType::List(ListType::new(string_to_int_map));
§Working with optional types
use cel_cxx::types::*;
// Optional string: optional<string>
let optional_string = ValueType::Optional(OptionalType::new(ValueType::String));
// Optional list: optional<list<int>>
let optional_list = ValueType::Optional(OptionalType::new(
ValueType::List(ListType::new(ValueType::Int))
));
§Working with function types
use cel_cxx::types::*;
// Function type: (string, int) -> bool
let func_type = ValueType::Function(FunctionType::new(
ValueType::Bool,
vec![ValueType::String, ValueType::Int]
));
Structs§
- Enum
Type - Enum type representing enumeration types.
- Function
Type - Function type representing function signatures.
- Invalid
MapKey Type - Error type for invalid map key type conversions.
- List
Type - List type representing ordered collections.
- MapType
- Map type representing key-value mappings.
- Opaque
Type - Opaque type for user-defined types.
- Optional
Type - Optional type representing values that may or may not be present.
- Struct
Type - Struct type for Protocol Buffer messages.
- Type
Param Type - Type parameter type used in generic type definitions.
- Type
Type - Type type representing type values.
Enums§
- MapKey
Type - Types that can be used as map keys.
- Value
Type - CEL type representation.