Crate owned_json_deserializer

Source
Expand description

§Owned JSON Deserializer

Crates.io Documentation License Dragon Powered

Because apparently serde_json only deserializes through a reference™.

§Usage

use serde::{Deserialize, Deserializer};
use owned_json_deserializer::OwnedJsonDeserializer;

#[derive(Deserialize)]
struct Wave {
    hi: String,
}

fn gimme_a_deserializer(say_hi_to: String) -> impl Deserializer<'static> { 
    OwnedJsonDeserializer::from_string(
        format!(r#"{{ "hi": "{}" }}"#, say_hi_to)
    )
}

fn main() {
    let deserializer = gimme_a_deserializer("mom".to_string());
    let wave = Wave::deserialize(deserializer).unwrap();
    assert_eq!(wave.hi, "mom");
}

§License

This crate is dual-licensed under either:

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Structs§

OwnedJsonDeserializer
A wrapper over serde_json::Deserializer where OwnedJsonDeserializer: serde::Deserializer.