Extract

Trait Extract 

Source
pub trait Extract<T>: Sized {
    // Required method
    fn extract(from: Value<T>) -> Option<Self>;
}
Expand description

A trait to denote types which can be extracted out of a Value<T>.

let value : Value<()> = Value::Integer(42);
assert_eq!(i64::extract(value), Some(42))

For each accessibility kind there is an Option variant, treating a Value as a Option<T>, where Value::Null denotes None and every other value is tried to get parsed into Some(t):


// any `Value::Null` is a `None`:
let value : Value<()> = Value::Null;
assert_eq!(<Option<String>>::extract(value), Some(None));

let value : Value<()> = Value::String(String::from("Hello World!"));
assert_eq!(<Option<String>>::extract(value), Some(Some(String::from("Hello World!"))));

Required Methods§

Source

fn extract(from: Value<T>) -> Option<Self>

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<T> Extract<T> for bool

Source§

fn extract(from: Value<T>) -> Option<Self>

Source§

impl<T> Extract<T> for f64

Source§

fn extract(from: Value<T>) -> Option<Self>

Source§

impl<T> Extract<T> for i64

Source§

fn extract(from: Value<T>) -> Option<Self>

Source§

impl<T> Extract<T> for String

Source§

fn extract(from: Value<T>) -> Option<Self>

Source§

impl<T> Extract<T> for Vec<Value<T>>

Source§

fn extract(from: Value<T>) -> Option<Self>

Source§

impl<T, E: Extract<T>> Extract<T> for Option<E>

Source§

fn extract(from: Value<T>) -> Option<Self>

Implementors§

Source§

impl<T> Extract<T> for Bytes

Source§

impl<T> Extract<T> for Dictionary<T>