mlb_api/requests/stats/wrappers/
accumulated_matchup.rs1use derive_more::{Deref, DerefMut};
2use serde::Deserialize;
3use crate::game_types::GameType;
4use crate::stats::{RawStat, SingletonSplitStat};
5use crate::stats::wrappers::{GameTypePiece, OpposingTeamPiece, TeamPiece};
6use crate::team::NamedTeam;
7
8#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Deref, DerefMut)]
9#[serde(rename_all = "camelCase")]
10#[serde(bound = "T: RawStat")]
11pub struct AccumulatedMatchup<T: RawStat> {
12 #[serde(rename = "opponent")]
13 pub opposing_team: NamedTeam,
14 pub game_type: GameType,
15 pub team: NamedTeam,
16
17 #[deref]
18 #[deref_mut]
19 #[serde(rename = "stat")]
20 pub stats: T,
21}
22
23impl<T: RawStat> OpposingTeamPiece for AccumulatedMatchup<T> {
24 fn opposing_team(&self) -> &NamedTeam {
25 &self.opposing_team
26 }
27}
28
29impl<T: RawStat> GameTypePiece for AccumulatedMatchup<T> {
30 fn game_type(&self) -> &GameType {
31 &self.game_type
32 }
33}
34
35impl<T: RawStat> TeamPiece for AccumulatedMatchup<T> {
36 fn team(&self) -> &NamedTeam {
37 &self.team
38 }
39}
40
41impl<T: RawStat> Default for AccumulatedMatchup<T> {
42 fn default() -> Self {
43 Self {
44 opposing_team: NamedTeam::unknown_team(),
45 game_type: GameType::default(),
46 team: NamedTeam::unknown_team(),
47
48 stats: T::default(),
49 }
50 }
51}
52
53impl<T: RawStat> SingletonSplitStat for AccumulatedMatchup<T> {}