mlb_api/endpoints/game/
mod.rs

1use derive_more::{Deref, Display, From};
2use serde::Deserialize;
3use std::ops::{Deref, DerefMut};
4use strum::EnumTryAs;
5
6pub mod boxscore;
7pub mod changes;
8pub mod color;
9pub mod content;
10pub mod context_metrics;
11pub mod diff;
12pub mod linescore;
13pub mod pace;
14pub mod pbp;
15pub mod timestamps;
16pub mod uniforms;
17pub mod win_probability;
18
19#[repr(transparent)]
20#[derive(Debug, Default, Deserialize, Deref, Display, PartialEq, Eq, Copy, Clone)]
21pub struct GameId(u32);
22
23impl GameId {
24	#[must_use]
25	pub const fn new(id: u32) -> Self {
26		Self(id)
27	}
28}
29
30#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
31pub struct IdentifiableGame {
32	#[serde(rename = "gamePk")]
33	pub id: GameId,
34}
35
36impl Default for IdentifiableGame {
37	fn default() -> Self {
38		Self { id: GameId::default() }
39	}
40}
41
42#[derive(Debug, Deserialize, Eq, Clone, From, EnumTryAs)]
43#[serde(untagged)]
44pub enum Game {
45	Identifiable(IdentifiableGame),
46}
47
48impl Default for Game {
49	fn default() -> Self {
50		Self::Identifiable(IdentifiableGame::default())
51	}
52}
53
54impl Deref for Game {
55	type Target = IdentifiableGame;
56
57	fn deref(&self) -> &Self::Target {
58		match self {
59			Self::Identifiable(inner) => inner,
60		}
61	}
62}
63
64impl DerefMut for Game {
65	fn deref_mut(&mut self) -> &mut Self::Target {
66		match self {
67			Self::Identifiable(inner) => inner,
68		}
69	}
70}
71
72impl PartialEq for Game {
73	fn eq(&self, other: &Self) -> bool {
74		self.id == other.id
75	}
76}