Trait FromJsonValue

Source
pub trait FromJsonValue
where Self: Sized,
{ // Required method fn from_json_value(value: Value) -> Result<Self, Error<Error>>; }

Required Methods§

Source

fn from_json_value(value: Value) -> Result<Self, Error<Error>>

Convert from serde_json::Value.

use serde::Deserialize;
use serde_valid::Validate;
use serde_valid::json::{json, FromJsonValue};

#[derive(Debug, Validate, Deserialize)]
struct TestStruct {
    #[validate(maximum = 2000)]
    val: i32,
}

let s = TestStruct::from_json_value(json!({ "val": 1234 }));

assert!(s.is_ok())

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.

Implementors§