Enum ValueType

Source
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

Source

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);
Source

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 implements TypedValue, 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

Trait Implementations§

Source§

impl Clone for ValueType

Source§

fn clone(&self) -> ValueType

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ValueType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ValueType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<EnumType> for ValueType

Source§

fn from(value: EnumType) -> Self

Converts to this type from the input type.
Source§

impl From<FunctionType> for ValueType

Source§

fn from(value: FunctionType) -> Self

Converts to this type from the input type.
Source§

impl From<ListType> for ValueType

Source§

fn from(value: ListType) -> Self

Converts to this type from the input type.
Source§

impl From<MapKeyType> for ValueType

Source§

fn from(key: MapKeyType) -> Self

Converts to this type from the input type.
Source§

impl From<MapType> for ValueType

Source§

fn from(value: MapType) -> Self

Converts to this type from the input type.
Source§

impl From<OpaqueType> for ValueType

Source§

fn from(value: OpaqueType) -> Self

Converts to this type from the input type.
Source§

impl From<OptionalType> for ValueType

Source§

fn from(value: OptionalType) -> Self

Converts to this type from the input type.
Source§

impl From<StructType> for ValueType

Source§

fn from(value: StructType) -> Self

Converts to this type from the input type.
Source§

impl From<TypeParamType> for ValueType

Source§

fn from(value: TypeParamType) -> Self

Converts to this type from the input type.
Source§

impl From<TypeType> for ValueType

Source§

fn from(value: TypeType) -> Self

Converts to this type from the input type.
Source§

impl From<ValueType> for Value

Source§

fn from(value: ValueType) -> Self

Converts to this type from the input type.
Source§

impl FromValue for &ValueType

Source§

type Output<'a> = &'a ValueType

The output type for the from_value method. Read more
Source§

fn from_value<'a>(value: &'a Value) -> Result<Self::Output<'a>, FromValueError>

Attempts to convert a CEL Value into this type. Read more
Source§

impl FromValue for ValueType

Source§

type Output<'a> = ValueType

The output type for the from_value method. Read more
Source§

fn from_value<'a>(value: &'a Value) -> Result<Self::Output<'a>, FromValueError>

Attempts to convert a CEL Value into this type. Read more
Source§

impl Hash for ValueType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoValue for ValueType

Source§

fn into_value(self) -> Value

Converts this value into a CEL Value. Read more
Source§

impl PartialEq for ValueType

Source§

fn eq(&self, other: &ValueType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<&'a Value> for &'a ValueType

Source§

type Error = FromValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &'a Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Value> for ValueType

Source§

type Error = FromValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, <Self as TryFrom<&Value>>::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for ValueType

Source§

type Error = FromValueError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, <Self as TryFrom<Value>>::Error>

Performs the conversion.
Source§

impl TryFrom<ValueType> for MapKeyType

Source§

type Error = InvalidMapKeyType

The type returned in the event of a conversion error.
Source§

fn try_from(value: ValueType) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TypedValue for ValueType

Source§

fn value_type() -> ValueType

Returns the CEL type for this value type. Read more
Source§

impl Eq for ValueType

Source§

impl StructuralPartialEq for ValueType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoResult for T
where T: IntoValue + TypedValue,

Source§

fn into_result(self) -> Result<Value, Error>

Convert the value into a CEL result.
Source§

fn value_type() -> ValueType

Get the CEL type of the resulting value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more