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
use std::fmt;
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
#[derive(Clone, PartialEq, Copy, Debug, EnumIter)]
pub enum Person {
Human,
Elf,
Dwarf,
Sprite,
}
impl Default for Person {
fn default() -> Self {
Self::Human
}
}
impl fmt::Display for Person {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v:String;
match *self {
Person::Human => v = String::from("Human"),
Person::Elf => v = String::from("Elf"),
Person::Dwarf => v = String::from("Dwarf"),
Person::Sprite => v = String::from("Sprite"),
}
write!(f, "{}", v.as_str())
}
}
#[derive(Clone, PartialEq, Copy, Debug, EnumIter)]
pub enum Animal {
Rat,
Snake,
Rabbit,
Wolf,
Crocodile,
}
impl Default for Animal {
fn default() -> Self {
Self::Rat
}
}
impl fmt::Display for Animal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v:String;
match *self {
Animal::Rat => v = String::from("Rat"),
Animal::Snake => v = String::from("Snake"),
Animal::Rabbit => v = String::from("Rabbit"),
Animal::Wolf => v = String::from("Wolf"),
Animal::Crocodile => v = String::from("Crocodile"),
}
write!(f, "{}", v.as_str())
}
}