Function serde_json_any_key::json_to_vec

source ·
pub fn json_to_vec<'a, K, V>(str: &'a str) -> Result<Vec<(K, V)>, Error>
where for<'de> K: Deserialize<'de> + Any, for<'de> V: Deserialize<'de>,
Expand description

Reverses to_json_map(), returning a Vec<(K,V)>.

§Examples

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 vec: Vec<(Test,Test)> = vec![(Test {a: 3, b: 5}, Test {a: 7, b: 9})];
 
let ser = vec.to_json_map().unwrap();
let deser: Vec<(Test,Test)> = json_to_vec(&ser).unwrap();

assert_eq!(vec, deser);
Ok(()) }
try_main().unwrap();