TryFromValue

Trait TryFromValue 

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

Source

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§

Source

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.

Implementations on Foreign Types§

Source§

impl TryFromValue for bool

Source§

impl TryFromValue for f32

Source§

impl TryFromValue for f64

Source§

impl TryFromValue for i8

Source§

impl TryFromValue for i16

Source§

impl TryFromValue for i32

Source§

impl TryFromValue for i64

Source§

impl TryFromValue for i128

Source§

impl TryFromValue for u8

Source§

impl TryFromValue for u16

Source§

impl TryFromValue for u32

Source§

impl TryFromValue for u64

Source§

impl TryFromValue for u128

Source§

impl TryFromValue for String

Implementors§