Crates.io | owned_json_deserializer |
lib.rs | owned_json_deserializer |
version | 1.0.0 |
source | src |
created_at | 2022-07-31 21:04:19.987877 |
updated_at | 2022-07-31 21:04:19.987877 |
description | Because apparently `serde_json` only deserializes through a referenceā¢. |
homepage | |
repository | https://github.com/Arc-blroth/owned_json_deserializer |
max_upload_size | |
id | 636334 |
size | 23,881 |
Because apparently serde_json
only deserializes through a referenceā¢.
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");
}
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.