Module types

Source
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 value
  • bool: Boolean values (true/false)
  • int: 64-bit signed integers
  • uint: 64-bit unsigned integers
  • double: Double-precision floating point numbers
  • string: UTF-8 encoded text
  • bytes: Byte arrays

§Time Types

  • duration: Time spans (from Protocol Buffers)
  • timestamp: Points in time (from Protocol Buffers)

§Collection Types

  • list<T>: Ordered sequences of values
  • map<K, V>: Key-value mappings

§Protocol Buffer Types

  • struct: Protocol Buffer messages
  • Wrapper types: BoolValue, StringValue, etc.
  • any: Can hold any Protocol Buffer message
  • enum: Protocol Buffer enumerations

§Advanced Types

  • type: Represents types themselves as values
  • function: Function signatures
  • optional<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§

EnumType
Enum type representing enumeration types.
FunctionType
Function type representing function signatures.
InvalidMapKeyType
Error type for invalid map key type conversions.
ListType
List type representing ordered collections.
MapType
Map type representing key-value mappings.
OpaqueType
Opaque type for user-defined types.
OptionalType
Optional type representing values that may or may not be present.
StructType
Struct type for Protocol Buffer messages.
TypeParamType
Type parameter type used in generic type definitions.
TypeType
Type type representing type values.

Enums§

MapKeyType
Types that can be used as map keys.
ValueType
CEL type representation.