Trait merde::ValueDeserialize

source ·
pub trait ValueDeserialize<'s>: Sized {
    // Required method
    fn from_value_ref<'val>(
        value: Option<&'val Value<'s>>,
    ) -> Result<Self, MerdeError>;

    // Provided method
    fn from_value(value: Option<Value<'s>>) -> Result<Self, MerdeError> { ... }
}
Expand description

Types that can be deserialized from a Value.

Implementations are provided for primitive types, strings, arrays, [HashMap], Option, etc.

There is no facility for “parsing strings as numbers”. However, this implementation does support numbers that are too big to fit (precisely) in an f64, ie. integers larger than 2**53.

A field of type HashMap<K, V> or Vec<T> is required! If you want to make it optional, wrap it in an Option<T> explicitly, e.g. Option<HashMap<K, V>> or Option<Vec<T>>.

Required Methods§

source

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<Self, MerdeError>

Destructures a Value into a more structured type

Provided Methods§

source

fn from_value(value: Option<Value<'s>>) -> Result<Self, MerdeError>

Destructures a JSON value into a Rust value, while taking ownership of the Value. A default implementation is provided, but some types may want to implement it themselves to avoid unnecessary allocations/cloning.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'s> ValueDeserialize<'s> for Cow<'s, str>

source§

fn from_value(value: Option<Value<'s>>) -> Result<Cow<'s, str>, MerdeError>

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<Cow<'s, str>, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for bool

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<bool, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for i8

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<i8, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for i16

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<i16, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for i32

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<i32, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for i64

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<i64, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for u8

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<u8, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for u16

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<u16, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for u32

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<u32, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for u64

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<u64, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for usize

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<usize, MerdeError>

source§

impl<'s> ValueDeserialize<'s> for String

source§

impl<'s, K, V> ValueDeserialize<'s> for HashMap<K, V>
where K: FromStr + Eq + Hash + 's, V: ValueDeserialize<'s>, <K as FromStr>::Err: Debug,

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<HashMap<K, V>, MerdeError>

source§

impl<'s, T> ValueDeserialize<'s> for Option<T>
where T: ValueDeserialize<'s>,

source§

fn from_value(value: Option<Value<'s>>) -> Result<Option<T>, MerdeError>

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<Option<T>, MerdeError>

source§

impl<'s, T> ValueDeserialize<'s> for Vec<T>
where T: ValueDeserialize<'s>,

source§

fn from_value_ref<'val>( value: Option<&'val Value<'s>>, ) -> Result<Vec<T>, MerdeError>

Implementors§

source§

impl<'s> ValueDeserialize<'s> for CowStr<'s>

source§

impl<'s> ValueDeserialize<'s> for Value<'s>

source§

impl<'s> ValueDeserialize<'s> for Array<'s>

source§

impl<'s> ValueDeserialize<'s> for Map<'s>