1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use serde_json::{Value as JsonValue, from_value as from_json_value};
use self::super::achievements::Achievements;
use serde::{Serialize, Deserialize, Deserializer};
use self::super::stats::Statistics;
use std::collections::BTreeMap;
use self::super::HeroPlaytime;
use std::fmt::Debug;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FullData {
pub eu: RegionalData,
pub us: RegionalData,
pub kr: RegionalData,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct RegionalData {
pub stats: Option<BiMode<Statistics>>,
pub achievements: Option<Achievements>,
pub heroes: Option<HeroesContainer>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BiMode<T: Debug + Clone + PartialEq + Serialize + Deserialize> {
pub competitive: T,
pub quickplay: T,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct HeroesContainer {
pub playtime: BiMode<HeroPlaytime>,
pub stats: BiMode<BTreeMap<String, JsonValue>>,
}
impl Deserialize for RegionalData {
fn deserialize<D: Deserializer>(deserializer: D) -> Result<Self, D::Error> {
let val: JsonValue = try!(Deserialize::deserialize(deserializer));
Ok(RegionalData {
stats: val.get("stats").into_iter().filter(|v| !v.is_null()).flat_map(|v| from_json_value(v.clone())).next(),
achievements: val.get("achievements").into_iter().filter(|v| !v.is_null()).flat_map(|v| from_json_value(v.clone())).next(),
heroes: val.get("heroes").into_iter().filter(|v| !v.is_null()).flat_map(|v| from_json_value(v.clone())).next(),
})
}
}