pub trait TryFromValue: Sized {
// Required method
fn try_from_value(value: &Value) -> Result<Self, FromValueError>;
// Provided method
fn from_value(value: &Value) -> Option<Self> { ... }
}Expand description
Trait for strict extraction of Rust types from Value.
This is the inverse of IntoValue. Each implementation only accepts
the exact matching Value variant (e.g., i64 only accepts Value::Int8).
For Undefined values or type mismatches, use from_value() which returns
Option<Self> for convenience.
Required Methods§
Sourcefn try_from_value(value: &Value) -> Result<Self, FromValueError>
fn try_from_value(value: &Value) -> Result<Self, FromValueError>
Attempt to extract a value of this type from a Value.
Returns an error if the Value variant doesn’t match the expected type.
Note: This does NOT handle Undefined - use from_value() for that.
Provided Methods§
Sourcefn from_value(value: &Value) -> Option<Self>
fn from_value(value: &Value) -> Option<Self>
Extract from Value, returning None for Undefined or type mismatch.
This is the recommended method for most use cases as it handles Undefined values gracefully.
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.