1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! Guardian deity types

use errors::UnknownVariant;

use std::fmt::{Display, Formatter, Result as FmtResult};
use std::str::FromStr;

/// The guardian deities in the game.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
pub enum Guardian {
    Althyk,
    Azeyma,
    Byregot,
    Halone,
    Llymlaen,
    Menphina,
    NaldThal,
    Nophica,
    Nymeia,
    Oschon,
    Rhalgr,
    Thaliak,
}

impl Guardian {
    #[cfg(feature = "all_const")]
    pub const ALL: [Guardian; 12] = [
        Guardian::Althyk,
        Guardian::Azeyma,
        Guardian::Byregot,
        Guardian::Halone,
        Guardian::Llymlaen,
        Guardian::Menphina,
        Guardian::NaldThal,
        Guardian::Nophica,
        Guardian::Nymeia,
        Guardian::Oschon,
        Guardian::Rhalgr,
        Guardian::Thaliak,
    ];

    /// Returns the string variant of this world.
    pub fn as_str(&self) -> &'static str {
        match *self {
            Guardian::Althyk => "Althyk",
            Guardian::Azeyma => "Azeyma",
            Guardian::Byregot => "Byregot",
            Guardian::Halone => "Halone",
            Guardian::Llymlaen => "Llymlaen",
            Guardian::Menphina => "Menphina",
            Guardian::NaldThal => "NaldThal",
            Guardian::Nophica => "Nophica",
            Guardian::Nymeia => "Nymeia",
            Guardian::Oschon => "Oschon",
            Guardian::Rhalgr => "Rhalgr",
            Guardian::Thaliak => "Thaliak",
        }
    }

    pub fn name(&self) -> &'static str {
        match *self {
            Guardian::Althyk => "Althyk",
            Guardian::Azeyma => "Azeyma",
            Guardian::Byregot => "Byregot",
            Guardian::Halone => "Halone",
            Guardian::Llymlaen => "Llymlaen",
            Guardian::Menphina => "Menphina",
            Guardian::NaldThal => "Nald'thal",
            Guardian::Nophica => "Nophica",
            Guardian::Nymeia => "Nymeia",
            Guardian::Oschon => "Oschon",
            Guardian::Rhalgr => "Rhalgr",
            Guardian::Thaliak => "Thaliak",
        }
    }

    pub fn epithet(&self) -> &'static str {
        match *self {
            Guardian::Althyk => "the Keeper",
            Guardian::Azeyma => "the Warden",
            Guardian::Byregot => "the Builder",
            Guardian::Halone => "the Fury",
            Guardian::Llymlaen => "the Navigator",
            Guardian::Menphina => "the Lover",
            Guardian::NaldThal => "the Traders",
            Guardian::Nophica => "the Matron",
            Guardian::Nymeia => "the Spinner",
            Guardian::Oschon => "the Wanderer",
            Guardian::Rhalgr => "the Destroyer",
            Guardian::Thaliak => "the Scholar",
        }
    }
}

impl FromStr for Guardian {
    type Err = UnknownVariant;

    /// Parses a string `s` to return a value of this type.
    ///
    /// This is case-insensitive.
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let guardian = match s.to_lowercase().as_str() {
            "althyk" => Guardian::Althyk,
            "azeyma" => Guardian::Azeyma,
            "byregot" => Guardian::Byregot,
            "halone" => Guardian::Halone,
            "llymlaen" => Guardian::Llymlaen,
            "menphina" => Guardian::Menphina,
            "naldthal" | "nald'thal" => Guardian::NaldThal,
            "nophica" => Guardian::Nophica,
            "nymeia" => Guardian::Nymeia,
            "oschon" => Guardian::Oschon,
            "rhalgr" => Guardian::Rhalgr,
            "thaliak" => Guardian::Thaliak,
            _ => return Err(UnknownVariant("Guardian", s.into()))
        };

        Ok(guardian)
    }
}

impl Display for Guardian {
    fn fmt(&self, f: &mut Formatter) -> FmtResult {
        write!(f, "{}", self.name())
    }
}