feat: deserialize test

main
phga 2 years ago
parent c39911ff45
commit fd2b49e190
Signed by: phga
GPG Key ID: 5249548AA705F019

@ -1,19 +1,19 @@
use std::collections::HashMap; use std::collections::HashMap;
use serde::Serialize; use serde::{Serialize, Deserialize};
use serde_with::serde_as; use serde_with::serde_as;
#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize)] #[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize)]
struct Path(pub Vec<u32>); struct Path(pub Vec<u32>);
#[derive(Serialize)] #[derive(Serialize, Deserialize, Debug)]
struct Rel { struct Rel {
path: Path, path: Path,
count: usize, count: usize,
} }
#[serde_as] #[serde_as]
#[derive(Serialize)] #[derive(Serialize, Deserialize)]
struct Cl1 { struct Cl1 {
#[serde_as(as = "Vec<(_, _)>")] #[serde_as(as = "Vec<(_, _)>")]
cache: HashMap<Vec<u32>, String>, cache: HashMap<Vec<u32>, String>,
@ -21,7 +21,7 @@ struct Cl1 {
type RelCache = HashMap<Path, Rel>; type RelCache = HashMap<Path, Rel>;
#[serde_as] #[serde_as]
#[derive(Serialize)] #[derive(Serialize, Deserialize, Debug)]
struct Cl2 { struct Cl2 {
#[serde_as(as = "Vec<(_, _)>")] #[serde_as(as = "Vec<(_, _)>")]
cache: RelCache, cache: RelCache,
@ -54,6 +54,8 @@ fn main() {
cache cache
}; };
let json = serde_json::to_string(&cl); let json = serde_json::to_string(&cl).unwrap();
dbg!(json); dbg!(&json);
let obj: Cl2 = serde_json::from_str(&json).unwrap();
dbg!(obj);
} }

Loading…
Cancel
Save