Trait TypedValue

Source
pub trait TypedValue {
    // Required method
    fn value_type() -> ValueType;
}
Expand description

Trait for types that have a known CEL type.

This trait provides type information for values that can be used in CEL expressions. It is used in conjunction with IntoValue and FromValue to provide complete type information for value conversions.

§Implementation

Important: This trait should generally not be implemented manually. For most use cases:

  • Built-in types: Already have implementations (primitives, collections, etc.)
  • Custom opaque types: Use the #[derive(Opaque)] macro which automatically implements this trait
  • Special cases: Only implement manually if you have very specific requirements

§Examples

§Using Built-in Types

use cel_cxx::{TypedValue, ValueType};

// Built-in types already implement TypedValue
assert_eq!(i64::value_type(), ValueType::Int);
assert_eq!(String::value_type(), ValueType::String);
assert_eq!(bool::value_type(), ValueType::Bool);

§Using Derive Macro for Custom Types

use cel_cxx::Opaque;

#[derive(Opaque, Debug, Clone, PartialEq)]
#[cel_cxx(display)]
struct CustomId(u64);

// TypedValue is automatically implemented by the derive macro

Required Methods§

Source

fn value_type() -> ValueType

Returns the CEL type for this value type.

This method provides the ValueType that corresponds to this Rust type in the CEL type system. It is used for type checking, error messages, and runtime type validation.

§Returns

The ValueType that represents this type in CEL expressions.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TypedValue for bool

Source§

impl TypedValue for f32

Source§

impl TypedValue for f64

Source§

impl TypedValue for i16

Source§

impl TypedValue for i32

Source§

impl TypedValue for i64

Source§

impl TypedValue for isize

Source§

impl TypedValue for str

Source§

impl TypedValue for u16

Source§

impl TypedValue for u32

Source§

impl TypedValue for u64

Source§

impl TypedValue for ()

Source§

impl TypedValue for usize

Source§

impl TypedValue for Box<str>

Source§

impl TypedValue for Box<[u8]>

Source§

impl TypedValue for String

Source§

impl TypedValue for Vec<u8>

Source§

impl TypedValue for SystemTime

Source§

impl TypedValue for [u8]

Source§

impl<K: TypedMapKey, V: TypedValue> TypedValue for BTreeMap<K, V>

Source§

impl<K: TypedMapKey, V: TypedValue> TypedValue for LinkedList<(K, V)>

Source§

impl<K: TypedMapKey, V: TypedValue> TypedValue for VecDeque<(K, V)>

Source§

impl<K: TypedMapKey, V: TypedValue> TypedValue for Vec<(K, V)>

Source§

impl<K: TypedMapKey, V: TypedValue> TypedValue for HashMap<K, V>

Source§

impl<K: TypedMapKey, V: TypedValue> TypedValue for [(K, V)]

Source§

impl<T: TypedValue + ?Sized> TypedValue for &T

Source§

impl<T: TypedValue + ?Sized> TypedValue for &mut T

Source§

impl<T: TypedValue> TypedValue for Option<T>

Source§

impl<T: TypedValue> TypedValue for [T]

Source§

impl<T: TypedValue> TypedValue for LinkedList<T>

Source§

impl<T: TypedValue> TypedValue for VecDeque<T>

Source§

impl<T: TypedValue> TypedValue for Vec<T>

Implementors§