mtg_data/
supertype.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 Supertype {
7    Basic,
8    Elite,
9    Legendary,
10    Ongoing,
11    Snow,
12    Token,
13    World,
14}
15
16impl std::str::FromStr for Supertype {
17    type Err = crate::ParsingError;
18    fn from_str(s: &str) -> Result<Self, Self::Err> {
19        match s {
20            "basic" => Ok(Self::Basic),
21            "elite" => Ok(Self::Elite),
22            "legendary" => Ok(Self::Legendary),
23            "ongoing" => Ok(Self::Ongoing),
24            "snow" => Ok(Self::Snow),
25            "token" => Ok(Self::Token),
26            "world" => Ok(Self::World),
27            _ => Err(crate::ParsingError {
28                item: "Supertype",
29                message: "provided source does not match",
30            }),
31        }
32    }
33}
34
35impl Supertype {
36    pub fn as_str(&self) -> &'static str {
37        match self {
38            Self::Basic => "basic",
39            Self::Elite => "elite",
40            Self::Legendary => "legendary",
41            Self::Ongoing => "ongoing",
42            Self::Snow => "snow",
43            Self::Token => "token",
44            Self::World => "world",
45        }
46    }
47}
48
49impl std::fmt::Display for Supertype {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        write!(f, "{}", self.as_str())
52    }
53}
54
55impl Supertype {
56    pub fn all() -> impl Iterator<Item = Self> {
57        [
58            Self::Basic,
59            Self::Elite,
60            Self::Legendary,
61            Self::Ongoing,
62            Self::Snow,
63            Self::Token,
64            Self::World,
65        ].into_iter()
66    }
67}