Trait FromJsonSlice

Source
pub trait FromJsonSlice<'de>
where Self: Sized,
{ // Required method fn from_json_slice(slice: &'de [u8]) -> Result<Self, Error<Error>>; }

Required Methods§

Source

fn from_json_slice(slice: &'de [u8]) -> Result<Self, Error<Error>>

Convert from json slice.

use serde::Deserialize;
use serde_valid::Validate;
use serde_valid::json::FromJsonSlice;

#[derive(Debug, Validate, Deserialize)]
struct TestStruct<'a> {
    #[validate(min_length = 1)]
    val: &'a str,
}

let s = TestStruct::from_json_slice(br#"{ "val": "abcde" }"#);

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§

Source§

impl<'de, T> FromJsonSlice<'de> for T
where T: Deserialize<'de> + Validate,