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 keysInt
: Signed integer keysUint
: Unsigned integer keysString
: 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
impl MapKey
Sourcepub fn kind(&self) -> Kind
pub fn kind(&self) -> Kind
Returns the kind of this map key.
Returns the corresponding Kind
enum.
Sourcepub fn mapkey_type(&self) -> MapKeyType
pub fn mapkey_type(&self) -> MapKeyType
Returns the type of this map key.
Returns the corresponding MapKeyType
enum.
Sourcepub fn from_value(value: Value) -> Result<Self, Value>
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 successfulErr(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());
Sourcepub fn into_value(self) -> Value
pub fn into_value(self) -> Value
Trait Implementations§
impl Eq for MapKey
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> 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
Mutably borrows from an owned value. Read more
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>
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 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>
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