rtdlib/types/
game_high_scores.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Contains a list of game high scores
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct GameHighScores {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// A list of game high scores
19  scores: Vec<GameHighScore>,
20  
21}
22
23impl RObject for GameHighScores {
24  #[doc(hidden)] fn td_name(&self) -> &'static str { "gameHighScores" }
25  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
26  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
27}
28
29
30
31impl GameHighScores {
32  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
33  pub fn builder() -> RTDGameHighScoresBuilder {
34    let mut inner = GameHighScores::default();
35    inner.td_name = "gameHighScores".to_string();
36    inner.extra = Some(Uuid::new_v4().to_string());
37    RTDGameHighScoresBuilder { inner }
38  }
39
40  pub fn scores(&self) -> &Vec<GameHighScore> { &self.scores }
41
42}
43
44#[doc(hidden)]
45pub struct RTDGameHighScoresBuilder {
46  inner: GameHighScores
47}
48
49impl RTDGameHighScoresBuilder {
50  pub fn build(&self) -> GameHighScores { self.inner.clone() }
51
52   
53  pub fn scores(&mut self, scores: Vec<GameHighScore>) -> &mut Self {
54    self.inner.scores = scores;
55    self
56  }
57
58}
59
60impl AsRef<GameHighScores> for GameHighScores {
61  fn as_ref(&self) -> &GameHighScores { self }
62}
63
64impl AsRef<GameHighScores> for RTDGameHighScoresBuilder {
65  fn as_ref(&self) -> &GameHighScores { &self.inner }
66}
67
68
69