Function serde_json_any_key::json_to_map
source · pub fn json_to_map<'a, K, V>(str: &'a str) -> Result<HashMap<K, V>, Error>
Expand description
Reverses to_json_map(), returning a HashMap<K,V>
.
§Examples
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use serde_json::Error;
use serde_json_any_key::*;
#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
pub struct Test {
pub a: i32,
pub b: i32
}
fn try_main() -> Result<(), Error> {
let mut map = HashMap::<Test, Test>::new();
map.insert(Test {a: 3, b: 5}, Test {a: 7, b: 9});
let ser = map.to_json_map().unwrap();
let deser: HashMap<Test, Test> = json_to_map(&ser).unwrap();
assert_eq!(map, deser);
Ok(()) }
try_main().unwrap();