pub enum ValueType {
Show 28 variants
Null,
Bool,
Int,
Uint,
Double,
String,
Bytes,
Struct(StructType),
Duration,
Timestamp,
List(ListType),
Map(MapType),
Unknown,
Type(TypeType),
Error,
Any,
Dyn,
Opaque(OpaqueType),
Optional(OptionalType),
BoolWrapper,
IntWrapper,
UintWrapper,
DoubleWrapper,
StringWrapper,
BytesWrapper,
TypeParam(TypeParamType),
Function(FunctionType),
Enum(EnumType),
}
Expand description
CEL type representation.
This enum represents all possible types in the CEL type system. CEL supports a rich type system including primitive types, complex types, and Protocol Buffer types. Each type corresponds to values that can be used in CEL expressions.
§Examples
§Basic Type Usage
use cel_cxx::*;
// Create different types
let int_type = ValueType::Int;
let string_type = ValueType::String;
let list_type = ValueType::List(ListType::new(ValueType::String));
// Check the kind of a type
assert_eq!(int_type.kind(), Kind::Int);
§Map Types
use cel_cxx::*;
let map_type = ValueType::Map(MapType::new(
MapKeyType::String,
ValueType::Int
));
assert_eq!(map_type.kind(), Kind::Map);
Variants§
Null
Null type - represents the absence of a value.
This corresponds to CEL’s null
literal.
Bool
Boolean type - represents true/false values.
This corresponds to CEL’s bool
type and literals like true
and false
.
Int
Signed 64-bit integer type.
This corresponds to CEL’s int
type and integer literals like 42
.
Uint
Unsigned 64-bit integer type.
This corresponds to CEL’s uint
type and unsigned integer literals like 42u
.
Double
Double-precision floating point type.
This corresponds to CEL’s double
type and floating-point literals like 3.14
.
String
String type.
This corresponds to CEL’s string
type and string literals like "hello"
.
Bytes
Byte array type.
This corresponds to CEL’s bytes
type and byte literals like b"hello"
.
Struct(StructType)
Struct type for Protocol Buffer messages.
This represents structured data types, typically Protocol Buffer messages.
Duration
Duration type from Protocol Buffers.
This corresponds to google.protobuf.Duration
and duration literals like duration("1h")
.
Timestamp
Timestamp type from Protocol Buffers.
This corresponds to google.protobuf.Timestamp
and timestamp literals like timestamp("2023-01-01T00:00:00Z")
.
List(ListType)
List type - represents ordered collections.
This corresponds to CEL’s list type and literals like [1, 2, 3]
.
Map(MapType)
Map type - represents key-value mappings.
This corresponds to CEL’s map type and literals like {"key": "value"}
.
Unknown
Unknown type - used for values that cannot be determined at compile time.
This is typically used in error conditions or for dynamic values.
Type(TypeType)
Type type - represents type values themselves.
This corresponds to CEL’s type system where types can be values, such as int
or string
.
Error
Error type - represents error values.
This is used when evaluation results in an error condition.
Any
Any type from Protocol Buffers.
This corresponds to google.protobuf.Any
which can hold any Protocol Buffer message.
Dyn
Dynamic type - represents values whose type is determined at runtime.
This is used for values that can be of any type.
Opaque(OpaqueType)
Opaque types - user-defined types that are not directly CEL types.
This allows integration of custom Rust types into CEL expressions.
Optional(OptionalType)
Optional type - represents values that may or may not be present.
This corresponds to CEL’s optional types and the optional
type constructor.
BoolWrapper
Boolean wrapper type from Protocol Buffers.
This corresponds to google.protobuf.BoolValue
.
IntWrapper
Integer wrapper type from Protocol Buffers.
This corresponds to google.protobuf.Int32Value
.
UintWrapper
Unsigned integer wrapper type from Protocol Buffers.
This corresponds to google.protobuf.UInt32Value
.
DoubleWrapper
Double wrapper type from Protocol Buffers.
This corresponds to google.protobuf.DoubleValue
.
StringWrapper
String wrapper type from Protocol Buffers.
This corresponds to google.protobuf.StringValue
.
BytesWrapper
Bytes wrapper type from Protocol Buffers.
This corresponds to google.protobuf.BytesValue
.
TypeParam(TypeParamType)
Type parameter type - used in generic type definitions.
This represents type parameters in generic contexts.
Function(FunctionType)
Function type - represents function signatures.
This is used to represent the types of functions and their signatures.
Enum(EnumType)
Enum type - represents enumeration types.
This corresponds to Protocol Buffer enum types.
Implementations§
Source§impl ValueType
impl ValueType
Sourcepub fn kind(&self) -> Kind
pub fn kind(&self) -> Kind
Returns the kind of this type.
The kind represents the basic category of the type, which is useful for type checking and dispatch logic.
§Examples
use cel_cxx::*;
assert_eq!(ValueType::Int.kind(), Kind::Int);
assert_eq!(ValueType::String.kind(), Kind::String);
let list_type = ValueType::List(ListType::new(ValueType::Int));
assert_eq!(list_type.kind(), Kind::List);
Sourcepub fn is<T: TypedValue>(&self) -> bool
pub fn is<T: TypedValue>(&self) -> bool
Checks if this type matches the type of a specific TypedValue
implementation.
This method provides a type-safe way to check if a ValueType
corresponds
to a particular Rust type that implements TypedValue
. It’s particularly
useful for runtime type checking and validation.
§Type Parameters
T
- A type that implementsTypedValue
, representing the Rust type to check against
§Returns
Returns true
if this ValueType
matches the CEL type representation of T
,
false
otherwise.
§Examples
§Basic Type Checking
use cel_cxx::*;
// Check primitive types
assert!(ValueType::Int.is::<i64>());
assert!(ValueType::String.is::<String>());
assert!(ValueType::Bool.is::<bool>());
// Check against wrong types
assert!(!ValueType::Int.is::<String>());
assert!(!ValueType::String.is::<bool>());
§Collection Type Checking
use cel_cxx::*;
use std::collections::HashMap;
let list_type = ValueType::List(ListType::new(ValueType::Int));
let map_type = ValueType::Map(MapType::new(MapKeyType::String, ValueType::Int));
// Check collection types
assert!(list_type.is::<Vec<i64>>());
assert!(map_type.is::<HashMap<String, i64>>());
// Check against incompatible collection types
assert!(!list_type.is::<Vec<String>>());
assert!(!map_type.is::<HashMap<i64, String>>());
§Optional Type Checking
use cel_cxx::*;
let optional_string = ValueType::Optional(OptionalType::new(ValueType::String));
// Check optional types
assert!(optional_string.is::<Option<String>>());
assert!(!optional_string.is::<Option<i64>>());
assert!(!optional_string.is::<String>()); // Not optional
§Custom Opaque Type Checking
use cel_cxx::*;
#[derive(Opaque, Debug, Clone, PartialEq)]
#[cel_cxx(type = "my.CustomType")]
struct CustomType {
value: i32,
}
impl std::fmt::Display for CustomType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CustomType({})", self.value)
}
}
let opaque_type = <CustomType as TypedValue>::value_type();
// Check custom opaque type
assert!(opaque_type.is::<CustomType>());
assert!(!opaque_type.is::<i32>());
§Use Cases
This method is commonly used in:
- Function implementations: Validating argument types before processing
- Type guards: Ensuring type safety in generic contexts
- Error handling: Providing detailed type mismatch error messages
- Debugging: Runtime inspection of type compatibility
§See Also
TypedValue::value_type()
: Get theValueType
representation of a Rust typeValueType::kind()
: Get the basic kind category of a type
Trait Implementations§
Source§impl From<FunctionType> for ValueType
impl From<FunctionType> for ValueType
Source§fn from(value: FunctionType) -> Self
fn from(value: FunctionType) -> Self
Source§impl From<MapKeyType> for ValueType
impl From<MapKeyType> for ValueType
Source§fn from(key: MapKeyType) -> Self
fn from(key: MapKeyType) -> Self
Source§impl From<OpaqueType> for ValueType
impl From<OpaqueType> for ValueType
Source§fn from(value: OpaqueType) -> Self
fn from(value: OpaqueType) -> Self
Source§impl From<OptionalType> for ValueType
impl From<OptionalType> for ValueType
Source§fn from(value: OptionalType) -> Self
fn from(value: OptionalType) -> Self
Source§impl From<StructType> for ValueType
impl From<StructType> for ValueType
Source§fn from(value: StructType) -> Self
fn from(value: StructType) -> Self
Source§impl From<TypeParamType> for ValueType
impl From<TypeParamType> for ValueType
Source§fn from(value: TypeParamType) -> Self
fn from(value: TypeParamType) -> Self
Source§impl TryFrom<ValueType> for MapKeyType
impl TryFrom<ValueType> for MapKeyType
Source§impl TypedValue for ValueType
impl TypedValue for ValueType
Source§fn value_type() -> ValueType
fn value_type() -> ValueType
impl Eq for ValueType
impl StructuralPartialEq for ValueType
Auto Trait Implementations§
impl Freeze for ValueType
impl RefUnwindSafe for ValueType
impl Send for ValueType
impl Sync for ValueType
impl Unpin for ValueType
impl UnwindSafe for ValueType
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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