pub struct FromMapKeyError { /* private fields */ }
Expand description
Error type for failed map key conversions.
This error is returned when attempting to convert a CEL MapKey
to a Rust type
using the FromMapKey
trait, but the conversion fails due to type mismatch.
§Error Information
The error contains:
- Source key: The original CEL map key that could not be converted
- Target type: The intended map key type for the conversion
§Map Key Constraints
Only certain types can be used as CEL map keys:
bool
- Boolean keysi64
- Signed integer keysu64
- Unsigned integer keysString
- String keys
§Common Causes
- Type mismatch: Trying to convert
MapKey::String
toi64
- Invalid key type: Attempting conversion to unsupported key type
- Format issues: Key value doesn’t meet target type constraints
§Examples
use cel_cxx::{MapKey, FromMapKey, FromMapKeyError};
let string_key = MapKey::String("not_a_number".to_string().into());
let result = i64::from_mapkey(&string_key);
match result {
Ok(num) => println!("Converted key: {}", num),
Err(error) => {
println!("Cannot convert key: {}", error);
}
}
Implementations§
Source§impl FromMapKeyError
impl FromMapKeyError
Sourcepub fn new(key: MapKey, to: MapKeyType) -> Self
pub fn new(key: MapKey, to: MapKeyType) -> Self
Create a new map key conversion error.
§Arguments
key
- The CEL map key that could not be convertedto
- The target map key type for the conversion
§Examples
use cel_cxx::{MapKey, MapKeyType, FromMapKeyError};
let error = FromMapKeyError::new(
MapKey::String("text".to_string().into()),
MapKeyType::Int
);
// Error created successfully
Sourcepub fn new_typed<T: TypedMapKey>(key: MapKey) -> Self
pub fn new_typed<T: TypedMapKey>(key: MapKey) -> Self
Create a new map key conversion error with automatic type detection.
This method uses the TypedMapKey
trait to automatically determine
the CEL type information of the target type, providing more consistent error messages.
§Type Parameters
T
- The target map key type that implementsTypedMapKey
§Arguments
key
- The CEL map key that could not be converted
§Examples
use cel_cxx::{MapKey, FromMapKeyError};
let error = FromMapKeyError::new_typed::<i64>(MapKey::String("text".to_string().into()));
// error contains type information for the target type
Trait Implementations§
Source§impl Clone for FromMapKeyError
impl Clone for FromMapKeyError
Source§fn clone(&self) -> FromMapKeyError
fn clone(&self) -> FromMapKeyError
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for FromMapKeyError
impl Debug for FromMapKeyError
Source§impl Display for FromMapKeyError
impl Display for FromMapKeyError
Source§impl Error for FromMapKeyError
impl Error for FromMapKeyError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<FromMapKeyError> for Error
impl From<FromMapKeyError> for Error
Source§fn from(error: FromMapKeyError) -> Self
fn from(error: FromMapKeyError) -> Self
Converts to this type from the input type.
Source§impl From<FromMapKeyError> for FromValueError
impl From<FromMapKeyError> for FromValueError
Source§fn from(error: FromMapKeyError) -> Self
fn from(error: FromMapKeyError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for FromMapKeyError
impl RefUnwindSafe for FromMapKeyError
impl Send for FromMapKeyError
impl Sync for FromMapKeyError
impl Unpin for FromMapKeyError
impl UnwindSafe for FromMapKeyError
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 moreSource§impl<E> IntoError for E
impl<E> IntoError for E
Source§fn into_error(self) -> Error
fn into_error(self) -> Error
Converts this value into a CEL error. Read more