mtg_data/
battle_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 BattleType {
7    Siege,
8}
9
10impl std::str::FromStr for BattleType {
11    type Err = crate::ParsingError;
12    fn from_str(s: &str) -> Result<Self, Self::Err> {
13        match s {
14            "siege" => Ok(Self::Siege),
15            _ => Err(crate::ParsingError {
16                item: "BattleType",
17                message: "provided source does not match",
18            }),
19        }
20    }
21}
22
23impl BattleType {
24    pub fn as_str(&self) -> &'static str {
25        match self {
26            Self::Siege => "siege",
27        }
28    }
29}
30
31impl std::fmt::Display for BattleType {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        write!(f, "{}", self.as_str())
34    }
35}
36
37impl BattleType {
38    pub fn all() -> impl Iterator<Item = Self> {
39        [
40            Self::Siege,
41        ].into_iter()
42    }
43}