You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.2 KiB

2 years ago
use std::collections::HashMap;
use serde::Serialize;
use serde_with::serde_as;
#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize)]
struct Path(pub Vec<u32>);
#[derive(Serialize)]
struct Rel {
path: Path,
count: usize,
}
#[serde_as]
#[derive(Serialize)]
struct Cl1 {
#[serde_as(as = "Vec<(_, _)>")]
cache: HashMap<Vec<u32>, String>,
}
type RelCache = HashMap<Path, Rel>;
#[serde_as]
#[derive(Serialize)]
struct Cl2 {
#[serde_as(as = "Vec<(_, _)>")]
cache: RelCache,
}
fn main() {
let mut cache = HashMap::new();
cache.insert(vec![1, 2, 3], "Erster Eintrag".to_owned());
cache.insert(vec![4, 5, 6], "Zweiter Eintrag".to_owned());
let cl = Cl1 {
cache
};
let json = serde_json::to_string(&cl);
dbg!(json);
let path1 = Path(vec![1, 2, 3]);
let path2 = Path(vec![4, 5, 6]);
let rel1 = Rel {
path: path1.clone(),
count: 37,
};
let rel2 = Rel {
path: path2.clone(),
count: 87,
};
let mut cache = RelCache::new();
cache.insert(path1, rel1);
cache.insert(path2, rel2);
let cl = Cl2 {
cache
};
let json = serde_json::to_string(&cl);
dbg!(json);
}