1use errors::UnknownVariant;
4
5use std::fmt::{Display, Formatter, Result as FmtResult};
6use std::str::FromStr;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[cfg_attr(feature = "with_serde", derive(Serialize, Deserialize))]
11pub enum Guardian {
12 Althyk,
13 Azeyma,
14 Byregot,
15 Halone,
16 Llymlaen,
17 Menphina,
18 NaldThal,
19 Nophica,
20 Nymeia,
21 Oschon,
22 Rhalgr,
23 Thaliak,
24}
25
26impl Guardian {
27 #[cfg(feature = "all_const")]
28 pub const ALL: [Guardian; 12] = [
29 Guardian::Althyk,
30 Guardian::Azeyma,
31 Guardian::Byregot,
32 Guardian::Halone,
33 Guardian::Llymlaen,
34 Guardian::Menphina,
35 Guardian::NaldThal,
36 Guardian::Nophica,
37 Guardian::Nymeia,
38 Guardian::Oschon,
39 Guardian::Rhalgr,
40 Guardian::Thaliak,
41 ];
42
43 pub fn as_str(&self) -> &'static str {
45 match *self {
46 Guardian::Althyk => "Althyk",
47 Guardian::Azeyma => "Azeyma",
48 Guardian::Byregot => "Byregot",
49 Guardian::Halone => "Halone",
50 Guardian::Llymlaen => "Llymlaen",
51 Guardian::Menphina => "Menphina",
52 Guardian::NaldThal => "NaldThal",
53 Guardian::Nophica => "Nophica",
54 Guardian::Nymeia => "Nymeia",
55 Guardian::Oschon => "Oschon",
56 Guardian::Rhalgr => "Rhalgr",
57 Guardian::Thaliak => "Thaliak",
58 }
59 }
60
61 pub fn name(&self) -> &'static str {
62 match *self {
63 Guardian::Althyk => "Althyk",
64 Guardian::Azeyma => "Azeyma",
65 Guardian::Byregot => "Byregot",
66 Guardian::Halone => "Halone",
67 Guardian::Llymlaen => "Llymlaen",
68 Guardian::Menphina => "Menphina",
69 Guardian::NaldThal => "Nald'thal",
70 Guardian::Nophica => "Nophica",
71 Guardian::Nymeia => "Nymeia",
72 Guardian::Oschon => "Oschon",
73 Guardian::Rhalgr => "Rhalgr",
74 Guardian::Thaliak => "Thaliak",
75 }
76 }
77
78 pub fn epithet(&self) -> &'static str {
79 match *self {
80 Guardian::Althyk => "the Keeper",
81 Guardian::Azeyma => "the Warden",
82 Guardian::Byregot => "the Builder",
83 Guardian::Halone => "the Fury",
84 Guardian::Llymlaen => "the Navigator",
85 Guardian::Menphina => "the Lover",
86 Guardian::NaldThal => "the Traders",
87 Guardian::Nophica => "the Matron",
88 Guardian::Nymeia => "the Spinner",
89 Guardian::Oschon => "the Wanderer",
90 Guardian::Rhalgr => "the Destroyer",
91 Guardian::Thaliak => "the Scholar",
92 }
93 }
94}
95
96impl FromStr for Guardian {
97 type Err = UnknownVariant;
98
99 fn from_str(s: &str) -> Result<Self, Self::Err> {
103 let guardian = match s.to_lowercase().as_str() {
104 "althyk" => Guardian::Althyk,
105 "azeyma" => Guardian::Azeyma,
106 "byregot" => Guardian::Byregot,
107 "halone" => Guardian::Halone,
108 "llymlaen" => Guardian::Llymlaen,
109 "menphina" => Guardian::Menphina,
110 "naldthal" | "nald'thal" => Guardian::NaldThal,
111 "nophica" => Guardian::Nophica,
112 "nymeia" => Guardian::Nymeia,
113 "oschon" => Guardian::Oschon,
114 "rhalgr" => Guardian::Rhalgr,
115 "thaliak" => Guardian::Thaliak,
116 _ => return Err(UnknownVariant("Guardian", s.into()))
117 };
118
119 Ok(guardian)
120 }
121}
122
123impl Display for Guardian {
124 fn fmt(&self, f: &mut Formatter) -> FmtResult {
125 write!(f, "{}", self.name())
126 }
127}