1 stable release
1.0.0 | Jul 31, 2022 |
---|
#1297 in Encoding
11KB
253 lines
Owned JSON Deserializer
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.
Dependencies
~0.5–1MB
~20K SLoC