mtg_data/
format.rs

1#[derive(idris_derive::Idris)]
2#[idris(repr = usize)]
3#[derive(serde::Serialize, serde::Deserialize)]
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
5#[cfg_attr(feature = "ts_export", derive(ts_rs::TS))]
6pub enum Format {
7    Alchemy,
8    Brawl,
9    Commander,
10    Duel,
11    Explorer,
12    Future,
13    Gladiator,
14    Historic,
15    HistoricBrawl,
16    Legacy,
17    Modern,
18    Oathbreaker,
19    Pauper,
20    PauperCommander,
21    Penny,
22    Pionner,
23    Predh,
24    Premodern,
25    Standard,
26    Vintage,
27}
28
29impl std::str::FromStr for Format {
30    type Err = crate::ParsingError;
31    fn from_str(s: &str) -> Result<Self, Self::Err> {
32        match s {
33            "alchemy" => Ok(Self::Alchemy),
34            "brawl" => Ok(Self::Brawl),
35            "commander" => Ok(Self::Commander),
36            "duel" => Ok(Self::Duel),
37            "explorer" => Ok(Self::Explorer),
38            "future" => Ok(Self::Future),
39            "gladiator" => Ok(Self::Gladiator),
40            "historic" => Ok(Self::Historic),
41            "historic brawl" => Ok(Self::HistoricBrawl),
42            "legacy" => Ok(Self::Legacy),
43            "modern" => Ok(Self::Modern),
44            "oathbreaker" => Ok(Self::Oathbreaker),
45            "pauper" => Ok(Self::Pauper),
46            "pauper commander" => Ok(Self::PauperCommander),
47            "penny" => Ok(Self::Penny),
48            "pionner" => Ok(Self::Pionner),
49            "predh" => Ok(Self::Predh),
50            "premodern" => Ok(Self::Premodern),
51            "standard" => Ok(Self::Standard),
52            "vintage" => Ok(Self::Vintage),
53            _ => Err(crate::ParsingError {
54                item: "Format",
55                message: "provided source does not match",
56            }),
57        }
58    }
59}
60
61impl Format {
62    pub fn as_str(&self) -> &'static str {
63        match self {
64            Self::Alchemy => "alchemy",
65            Self::Brawl => "brawl",
66            Self::Commander => "commander",
67            Self::Duel => "duel",
68            Self::Explorer => "explorer",
69            Self::Future => "future",
70            Self::Gladiator => "gladiator",
71            Self::Historic => "historic",
72            Self::HistoricBrawl => "historic brawl",
73            Self::Legacy => "legacy",
74            Self::Modern => "modern",
75            Self::Oathbreaker => "oathbreaker",
76            Self::Pauper => "pauper",
77            Self::PauperCommander => "pauper commander",
78            Self::Penny => "penny",
79            Self::Pionner => "pionner",
80            Self::Predh => "predh",
81            Self::Premodern => "premodern",
82            Self::Standard => "standard",
83            Self::Vintage => "vintage",
84        }
85    }
86}
87
88impl std::fmt::Display for Format {
89    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90        write!(f, "{}", self.as_str())
91    }
92}
93
94impl Format {
95    pub fn all() -> impl Iterator<Item = Self> {
96        [
97            Self::Alchemy,
98            Self::Brawl,
99            Self::Commander,
100            Self::Duel,
101            Self::Explorer,
102            Self::Future,
103            Self::Gladiator,
104            Self::Historic,
105            Self::HistoricBrawl,
106            Self::Legacy,
107            Self::Modern,
108            Self::Oathbreaker,
109            Self::Pauper,
110            Self::PauperCommander,
111            Self::Penny,
112            Self::Pionner,
113            Self::Predh,
114            Self::Premodern,
115            Self::Standard,
116            Self::Vintage,
117        ].into_iter()
118    }
119}