mtg_data/
land_type.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 LandType {
7    Cave,
8    Cloud,
9    Desert,
10    Forest,
11    Gate,
12    Island,
13    Lair,
14    Locus,
15    Mine,
16    Mountain,
17    Plains,
18    Planet,
19    PowerPlant,
20    Sphere,
21    Swamp,
22    Tower,
23    Town,
24    Urzas,
25}
26
27impl std::str::FromStr for LandType {
28    type Err = crate::ParsingError;
29    fn from_str(s: &str) -> Result<Self, Self::Err> {
30        match s {
31            "cave" => Ok(Self::Cave),
32            "cloud" => Ok(Self::Cloud),
33            "desert" => Ok(Self::Desert),
34            "forest" => Ok(Self::Forest),
35            "gate" => Ok(Self::Gate),
36            "island" => Ok(Self::Island),
37            "lair" => Ok(Self::Lair),
38            "locus" => Ok(Self::Locus),
39            "mine" => Ok(Self::Mine),
40            "mountain" => Ok(Self::Mountain),
41            "plains" => Ok(Self::Plains),
42            "planet" => Ok(Self::Planet),
43            "power-plant" => Ok(Self::PowerPlant),
44            "sphere" => Ok(Self::Sphere),
45            "swamp" => Ok(Self::Swamp),
46            "tower" => Ok(Self::Tower),
47            "town" => Ok(Self::Town),
48            "urza's" => Ok(Self::Urzas),
49            _ => Err(crate::ParsingError {
50                item: "LandType",
51                message: "provided source does not match",
52            }),
53        }
54    }
55}
56
57impl LandType {
58    pub fn as_str(&self) -> &'static str {
59        match self {
60            Self::Cave => "cave",
61            Self::Cloud => "cloud",
62            Self::Desert => "desert",
63            Self::Forest => "forest",
64            Self::Gate => "gate",
65            Self::Island => "island",
66            Self::Lair => "lair",
67            Self::Locus => "locus",
68            Self::Mine => "mine",
69            Self::Mountain => "mountain",
70            Self::Plains => "plains",
71            Self::Planet => "planet",
72            Self::PowerPlant => "power-plant",
73            Self::Sphere => "sphere",
74            Self::Swamp => "swamp",
75            Self::Tower => "tower",
76            Self::Town => "town",
77            Self::Urzas => "urza's",
78        }
79    }
80}
81
82impl std::fmt::Display for LandType {
83    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84        write!(f, "{}", self.as_str())
85    }
86}
87
88impl LandType {
89    pub fn all() -> impl Iterator<Item = Self> {
90        [
91            Self::Cave,
92            Self::Cloud,
93            Self::Desert,
94            Self::Forest,
95            Self::Gate,
96            Self::Island,
97            Self::Lair,
98            Self::Locus,
99            Self::Mine,
100            Self::Mountain,
101            Self::Plains,
102            Self::Planet,
103            Self::PowerPlant,
104            Self::Sphere,
105            Self::Swamp,
106            Self::Tower,
107            Self::Town,
108            Self::Urzas,
109        ].into_iter()
110    }
111}