mtg_data/
enchantment_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 EnchantmentType {
7    Aura,
8    Background,
9    Cartouche,
10    Case,
11    Class,
12    Curse,
13    Role,
14    Room,
15    Rune,
16    Saga,
17    Shard,
18    Shrine,
19}
20
21impl std::str::FromStr for EnchantmentType {
22    type Err = crate::ParsingError;
23    fn from_str(s: &str) -> Result<Self, Self::Err> {
24        match s {
25            "aura" => Ok(Self::Aura),
26            "background" => Ok(Self::Background),
27            "cartouche" => Ok(Self::Cartouche),
28            "case" => Ok(Self::Case),
29            "class" => Ok(Self::Class),
30            "curse" => Ok(Self::Curse),
31            "role" => Ok(Self::Role),
32            "room" => Ok(Self::Room),
33            "rune" => Ok(Self::Rune),
34            "saga" => Ok(Self::Saga),
35            "shard" => Ok(Self::Shard),
36            "shrine" => Ok(Self::Shrine),
37            _ => Err(crate::ParsingError {
38                item: "EnchantmentType",
39                message: "provided source does not match",
40            }),
41        }
42    }
43}
44
45impl EnchantmentType {
46    pub fn as_str(&self) -> &'static str {
47        match self {
48            Self::Aura => "aura",
49            Self::Background => "background",
50            Self::Cartouche => "cartouche",
51            Self::Case => "case",
52            Self::Class => "class",
53            Self::Curse => "curse",
54            Self::Role => "role",
55            Self::Room => "room",
56            Self::Rune => "rune",
57            Self::Saga => "saga",
58            Self::Shard => "shard",
59            Self::Shrine => "shrine",
60        }
61    }
62}
63
64impl std::fmt::Display for EnchantmentType {
65    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66        write!(f, "{}", self.as_str())
67    }
68}
69
70impl EnchantmentType {
71    pub fn all() -> impl Iterator<Item = Self> {
72        [
73            Self::Aura,
74            Self::Background,
75            Self::Cartouche,
76            Self::Case,
77            Self::Class,
78            Self::Curse,
79            Self::Role,
80            Self::Room,
81            Self::Rune,
82            Self::Saga,
83            Self::Shard,
84            Self::Shrine,
85        ].into_iter()
86    }
87}