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

Loading…
Cancel
Save