owned_json_deserializer

Crates.ioowned_json_deserializer
lib.rsowned_json_deserializer
version1.0.0
sourcesrc
created_at2022-07-31 21:04:19.987877
updated_at2022-07-31 21:04:19.987877
descriptionBecause apparently `serde_json` only deserializes through a referenceā„¢.
homepage
repositoryhttps://github.com/Arc-blroth/owned_json_deserializer
max_upload_size
id636334
size23,881
Andrew (Arc-blroth)

documentation

README

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.

Commit count: 1

cargo fmt