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