Skip to main content

mlb_api/requests/stats/wrappers/
season.rs

1use derive_more::{Deref, DerefMut};
2use serde::Deserialize;
3use crate::season::SeasonId;
4use crate::stats::{RawStat, SingletonSplitStat};
5use crate::stats::wrappers::SeasonPiece;
6
7#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Deref, DerefMut)]
8#[serde(bound = "T: RawStat")]
9pub struct WithSeason<T: RawStat> {
10	pub season: SeasonId,
11
12	#[deref]
13	#[deref_mut]
14	#[serde(rename = "stat")]
15	pub stats: T,
16}
17
18impl<T: RawStat> SeasonPiece for WithSeason<T> {
19	fn season(&self) -> &SeasonId {
20		&self.season
21	}
22}
23
24impl<T: RawStat> Default for WithSeason<T> {
25	fn default() -> Self {
26		Self {
27			season: SeasonId::current_season(),
28			stats: T::default(),
29		}
30	}
31}
32
33impl<T: RawStat> SingletonSplitStat for WithSeason<T> {
34
35}