mlb_api/requests/stats/wrappers/
mod.rs1mod career;
2mod map;
3mod season;
4mod position_and_season;
5mod team;
6mod game;
7mod player;
8mod player_and_team;
9mod single_matchup;
10mod accumulated_matchup;
11mod accumulated_vs_player_matchup;
12mod accumulated_vs_team;
13mod accumulated_vs_team_seasonal;
14mod month;
15mod weekday;
16mod home_away;
17mod win_loss;
18mod with_none;
19
20pub use career::*;
21pub use map::*;
22pub use season::*;
23pub use position_and_season::*;
24pub use team::*;
25pub use game::*;
26pub use player::*;
27pub use player_and_team::*;
28pub use single_matchup::*;
29pub use accumulated_matchup::*;
30pub use accumulated_vs_player_matchup::*;
31pub use accumulated_vs_team::*;
32pub use accumulated_vs_team_seasonal::*;
33pub use month::*;
34pub use weekday::*;
35pub use home_away::*;
36pub use win_loss::*;
37pub use with_none::*;
38
39use std::convert::Infallible;
40use std::fmt::Debug;
41use chrono::{Month, Weekday};
42use serde::de::DeserializeOwned;
43use crate::game::GameId;
44use crate::meta::GameType;
45use crate::league::NamedLeague;
46use crate::person::NamedPerson;
47use crate::meta::NamedPosition;
48use crate::season::SeasonId;
49use crate::stats::Stat;
50use crate::team::NamedTeam;
51
52impl<T: Debug + DeserializeOwned + PartialEq + Clone> Stat for Vec<T> {
53 type Split = T;
54 type TryFromSplitError = Infallible;
55
56 fn from_splits(splits: impl Iterator<Item=Self::Split>) -> Result<Self, Self::TryFromSplitError>
57 where
58 Self: Sized
59 {
60 Ok(splits.collect::<Self>())
61 }
62}
63
64macro_rules! piece {
65 ($name:ident => $ty:ty) => {
66 $crate::macro_use::pastey::paste! {
67 pub trait [<$name Piece>] {
68 fn [<$name:snake>](&self) -> &$ty;
69 }
70
71 pub struct [<By $name>];
72
73 impl<T: [<$name Piece>]> MapKey<T> for [<By $name>] {
74 type Key = $ty;
75
76 fn get_key(this: &T) -> Self::Key { this.[<$name:snake>]().clone() }
77 }
78 }
79 };
80}
81
82piece!(Season => SeasonId);
83piece!(Month => Month);
84piece!(Weekday => Weekday);
85piece!(Position => NamedPosition);
86piece!(OpposingTeam => NamedTeam);
87piece!(GameType => GameType);
88piece!(Team => NamedTeam);
89piece!(Pitcher => NamedPerson);
90piece!(Batter => NamedPerson);
91piece!(Player => NamedPerson);
92piece!(Game => GameId);
93piece!(League => NamedLeague);