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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct PlayerResult {
#[serde(rename = "username")]
pub username: String,
#[serde(rename = "rating")]
pub rating: i32,
#[serde(rename = "result")]
pub result: Result,
#[serde(rename = "@id")]
pub id: String,
}
impl PlayerResult {
pub fn new(username: String, rating: i32, result: Result, id: String) -> PlayerResult {
PlayerResult {
username,
rating,
result,
id,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Result {
#[serde(rename = "win")]
Win,
#[serde(rename = "checkmated")]
Checkmated,
#[serde(rename = "agreed")]
Agreed,
#[serde(rename = "repetition")]
Repetition,
#[serde(rename = "timeout")]
Timeout,
#[serde(rename = "resigned")]
Resigned,
#[serde(rename = "stalemate")]
Stalemate,
#[serde(rename = "lose")]
Lose,
#[serde(rename = "insufficient")]
Insufficient,
#[serde(rename = "50move")]
_50move,
#[serde(rename = "abandoned")]
Abandoned,
#[serde(rename = "kingofthehill")]
Kingofthehill,
#[serde(rename = "threecheck")]
Threecheck,
#[serde(rename = "timevsinsufficient")]
Timevsinsufficient,
#[serde(rename = "bughousepartnerlose")]
Bughousepartnerlose,
}
impl std::fmt::Display for Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Result::Win => write!(f, "win"),
Result::Checkmated => write!(f, "checkmated"),
Result::Agreed => write!(f, "agreed"),
Result::Repetition => write!(f, "repetition"),
Result::Timeout => write!(f, "timeout"),
Result::Resigned => write!(f, "resigned"),
Result::Stalemate => write!(f, "stalemate"),
Result::Lose => write!(f, "lose"),
Result::Insufficient => write!(f, "insufficient"),
Result::_50move => write!(f, "50move"),
Result::Abandoned => write!(f, "abandoned"),
Result::Kingofthehill => write!(f, "kingofthehill"),
Result::Threecheck => write!(f, "threecheck"),
Result::Timevsinsufficient => write!(f, "timevsinsufficient"),
Result::Bughousepartnerlose => write!(f, "bughousepartnerlose"),
}
}
}