pub struct FromValueError { /* private fields */ }
Expand description
Error type for failed value conversions.
This error is returned when attempting to convert a CEL Value
to a Rust type
using the FromValue
trait, but the conversion fails due to type mismatch.
§Error Information
The error contains:
- Source value: The original CEL value that could not be converted
- Target type: String description of the intended conversion target
- Context: Additional information about why the conversion failed
§Common Causes
- Type mismatch: Trying to convert
Value::String
toi64
- Invalid format: Trying to convert malformed data
- Constraint violation: Value doesn’t meet type constraints
§Examples
use cel_cxx::{Value, FromValue, FromValueError};
let string_val = Value::String("not_a_number".to_string().into());
let result = i64::from_value(&string_val);
match result {
Ok(num) => println!("Converted: {}", num),
Err(error) => {
println!("Cannot convert value: {}", error);
}
}
Implementations§
Source§impl FromValueError
impl FromValueError
Sourcepub fn new(value: Value, to: impl ToString) -> Self
pub fn new(value: Value, to: impl ToString) -> Self
Create a new conversion error with a custom target type description.
§Arguments
value
- The CEL value that could not be convertedto
- Description of the target type (will be converted to string)
§Examples
use cel_cxx::{Value, FromValueError};
let error = FromValueError::new(Value::String("text".to_string().into()), "integer");
// Error created successfully with custom type description
Sourcepub fn new_typed<T: TypedValue>(value: Value) -> Self
pub fn new_typed<T: TypedValue>(value: Value) -> Self
Create a new conversion error with automatic type name detection.
This method uses the TypedValue
trait to automatically determine
the CEL type information of the target type, providing more consistent error messages.
§Type Parameters
T
- The target type that implementsTypedValue
§Arguments
value
- The CEL value that could not be converted
§Examples
use cel_cxx::{Value, FromValueError};
let error = FromValueError::new_typed::<i64>(Value::String("text".to_string().into()));
// error contains type information for the target type
Trait Implementations§
Source§impl Clone for FromValueError
impl Clone for FromValueError
Source§fn clone(&self) -> FromValueError
fn clone(&self) -> FromValueError
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 FromValueError
impl Debug for FromValueError
Source§impl Display for FromValueError
impl Display for FromValueError
Source§impl Error for FromValueError
impl Error for FromValueError
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 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.
Source§impl From<FromValueError> for Error
impl From<FromValueError> for Error
Source§fn from(error: FromValueError) -> Self
fn from(error: FromValueError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for FromValueError
impl !RefUnwindSafe for FromValueError
impl Send for FromValueError
impl Sync for FromValueError
impl Unpin for FromValueError
impl !UnwindSafe for FromValueError
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