solution-rpm/src/race.rs
2024-06-10 08:19:19 +02:00

30 lines
769 B
Rust

// This file is just an enum of different races along with some implementations for it.
/// Different races that a player can choose from
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Race {
Elf,
Human,
Orc,
}
// There is a crate that can generate this with a macro. It's called strum.
impl Race {
pub const ALL: [Race; 3] = [Race::Elf, Race::Human, Race::Orc];
pub fn to_string(&self) -> &str {
match self {
Race::Elf => "Elf",
Race::Human => "Human",
Race::Orc => "Orc",
}
}
}
// We use this in the user interface
impl std::fmt::Display for Race {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.to_string())
}
}