Enum MapKey

Source
pub enum MapKey {
    Bool(bool),
    Int(i64),
    Uint(u64),
    String(ArcStr),
}
Expand description

CEL map key type.

MapKey represents value types that can be used as CEL map keys. According to the CEL specification, only basic comparable types can be used as map keys.

§Supported Key Types

  • Bool: Boolean keys
  • Int: Signed integer keys
  • Uint: Unsigned integer keys
  • String: String keys

§Examples

use cel_cxx::{MapKey, Value};
use std::collections::HashMap;

let mut map = HashMap::new();

// Different types of keys
map.insert(MapKey::String("name".to_string().into()), Value::String("Alice".to_string().into()));
map.insert(MapKey::Int(42), Value::String("answer".to_string().into()));
map.insert(MapKey::Bool(true), Value::String("yes".to_string().into()));

let map_value = Value::Map(map);

Variants§

§

Bool(bool)

Boolean key

§

Int(i64)

Signed integer key

§

Uint(u64)

Unsigned integer key

§

String(ArcStr)

String key

Implementations§

Source§

impl MapKey

Source

pub fn kind(&self) -> Kind

Returns the kind of this map key.

Returns the corresponding Kind enum.

Source

pub fn mapkey_type(&self) -> MapKeyType

Returns the type of this map key.

Returns the corresponding MapKeyType enum.

Source

pub fn from_value(value: Value) -> Result<Self, Value>

Creates a map key from a CEL value.

Attempts to convert a Value to MapKey. Only supported basic types can be converted successfully.

§Parameters
  • value: The CEL value to convert
§Returns
  • Ok(MapKey): Conversion successful
  • Err(Value): Conversion failed, returns original value
§Examples
use cel_cxx::{Value, MapKey};

// Successful conversion
let key = MapKey::from_value(Value::String("key".to_string().into())).unwrap();
assert_eq!(key, MapKey::String("key".to_string().into()));

// Failed conversion
let result = MapKey::from_value(Value::List(vec![]));
assert!(result.is_err());
Source

pub fn into_value(self) -> Value

Converts this map key to a CEL value.

Converts MapKey to the corresponding Value.

§Examples
use cel_cxx::{MapKey, Value};

let key = MapKey::String("hello".to_string().into());
let value = key.into_value();
assert_eq!(value, Value::String("hello".to_string().into()));

Trait Implementations§

Source§

impl Clone for MapKey

Source§

fn clone(&self) -> MapKey

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 MapKey

Source§

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

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

impl Display for MapKey

Source§

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

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

impl From<&str> for MapKey

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<ArcSlice<str>> for MapKey

Source§

fn from(value: ArcStr) -> Self

Converts to this type from the input type.
Source§

impl From<Box<str>> for MapKey

Source§

fn from(value: Box<str>) -> Self

Converts to this type from the input type.
Source§

impl From<MapKey> for Value

Source§

fn from(key: MapKey) -> Self

Converts to this type from the input type.
Source§

impl From<String> for MapKey

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for MapKey

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for MapKey

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for MapKey

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for MapKey

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for MapKey

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for MapKey

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for MapKey

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for MapKey

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for MapKey

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl Hash for MapKey

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 PartialEq for MapKey

Source§

fn eq(&self, other: &MapKey) -> 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 MapKey> for &'a ArcStr

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &'a MapKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a MapKey> for &'a bool

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &'a MapKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a MapKey> for &'a i64

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &'a MapKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a MapKey> for &'a str

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &'a MapKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a MapKey> for &'a u64

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &'a MapKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for ArcStr

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for Box<str>

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for String

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for bool

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for i16

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for i32

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for i64

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for isize

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for u16

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for u32

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for u64

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<&MapKey> for usize

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: &MapKey) -> Result<Self, <Self as TryFrom<&MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for ArcStr

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for Box<str>

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for String

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for bool

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for i16

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for i32

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for i64

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for isize

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for u16

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for u32

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for u64

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<MapKey> for usize

Source§

type Error = FromMapKeyError

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

fn try_from(mapkey: MapKey) -> Result<Self, <Self as TryFrom<MapKey>>::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for MapKey

Source§

type Error = FromValueError

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

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

Performs the conversion.
Source§

impl Eq for MapKey

Source§

impl StructuralPartialEq for MapKey

Auto Trait Implementations§

§

impl Freeze for MapKey

§

impl RefUnwindSafe for MapKey

§

impl Send for MapKey

§

impl Sync for MapKey

§

impl Unpin for MapKey

§

impl UnwindSafe for MapKey

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> 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