Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created March 18, 2018 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitsuhiko/ee7589eeaa7371622e9579e02a8e1300 to your computer and use it in GitHub Desktop.
Save mitsuhiko/ee7589eeaa7371622e9579e02a8e1300 to your computer and use it in GitHub Desktop.
#[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());
}
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