Created
March 18, 2018 19:54
-
-
Save mitsuhiko/ee7589eeaa7371622e9579e02a8e1300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] extern crate serde_derive; | |
extern crate serde_json; | |
use std::collections::HashMap; | |
#[derive(Debug, PartialEq, Serialize, Deserialize)] | |
#[serde(tag = "type")] | |
enum X { | |
Hash { x: HashMap<u32, u32> }, | |
} | |
fn main() { | |
println!("{:#?}", serde_json::from_str::<X>(r#" | |
{ | |
"type": "Hash", | |
"x": { | |
"1": 42, | |
"2": 23 | |
} | |
} | |
"#).unwrap()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: | |
ErrorImpl { code: Message("invalid type: string \"1\", expected u32"), line: 0, column: 0 }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment