mlb_api/requests/meta/
stat_groups.rs1use derive_more::{Display, FromStr};
2use serde::Deserialize;
3
4#[derive(Debug, Deserialize, PartialEq, Eq, Copy, Clone, FromStr, Hash, Display)]
5#[serde(try_from = "__StatGroupMaybeInline")]
6pub enum StatGroup {
7 Hitting,
8 Pitching,
9 Fielding,
10 Catching,
11 Running,
12 Game,
13 Team,
14 Streak,
15}
16
17#[derive(Deserialize)]
18#[serde(untagged)]
19#[doc(hidden)]
20enum __StatGroupMaybeInline {
21 Wrapped {
22 #[serde(rename = "displayName")]
23 display_name: String,
24 },
25 Inline(String),
26}
27
28impl __StatGroupMaybeInline {
29 #[must_use]
30 pub fn into_string(self) -> String {
31 match self {
32 Self::Wrapped { display_name } => display_name,
33 Self::Inline(name) => name,
34 }
35 }
36}
37
38impl TryFrom<__StatGroupMaybeInline> for StatGroup {
39 type Error = derive_more::FromStrError;
40
41 fn try_from(value: __StatGroupMaybeInline) -> Result<Self, Self::Error> {
42 value.into_string().parse::<Self>()
43 }
44}
45
46meta_kind_impl!("statGroups" => StatGroup);
47static_request_entry_cache_impl!(StatGroup);
48test_impl!(StatGroup);