generated from GarandPLG/rust-flake-template
Extract helper methods for enum trait implementations
This commit is contained in:
@@ -8,52 +8,39 @@ pub enum Structures {
|
||||
Stone(Stone),
|
||||
}
|
||||
|
||||
impl Structure for Structures {
|
||||
fn get_color(&self) -> Color {
|
||||
impl Structures {
|
||||
#[inline]
|
||||
fn structure(&self) -> &dyn Structure {
|
||||
match self {
|
||||
Self::Base(b) => b.get_color(),
|
||||
Self::Tunnel(t) => t.get_color(),
|
||||
Self::Stone(s) => s.get_color(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_tag(&self) -> char {
|
||||
match self {
|
||||
Self::Base(b) => b.get_tag(),
|
||||
Self::Tunnel(t) => t.get_tag(),
|
||||
Self::Stone(s) => s.get_tag(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_level(&self) -> char {
|
||||
match self {
|
||||
Self::Base(b) => b.get_level(),
|
||||
Self::Tunnel(t) => t.get_level(),
|
||||
Self::Stone(s) => s.get_level(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Base(b) => b.get_name(),
|
||||
Self::Tunnel(t) => t.get_name(),
|
||||
Self::Stone(s) => s.get_name(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_durability(&self) -> u16 {
|
||||
match self {
|
||||
Self::Base(b) => b.get_durability(),
|
||||
Self::Tunnel(t) => t.get_durability(),
|
||||
Self::Stone(s) => s.get_durability(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_stress(&self) -> u8 {
|
||||
match self {
|
||||
Self::Base(b) => b.get_stress(),
|
||||
Self::Tunnel(t) => t.get_stress(),
|
||||
Self::Stone(s) => s.get_stress(),
|
||||
Self::Base(b) => b,
|
||||
Self::Tunnel(t) => t,
|
||||
Self::Stone(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Structure for Structures {
|
||||
fn get_color(&self) -> Color {
|
||||
self.structure().get_color()
|
||||
}
|
||||
|
||||
fn get_tag(&self) -> char {
|
||||
self.structure().get_tag()
|
||||
}
|
||||
|
||||
fn get_level(&self) -> char {
|
||||
self.structure().get_level()
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &'static str {
|
||||
self.structure().get_name()
|
||||
}
|
||||
|
||||
fn get_durability(&self) -> u16 {
|
||||
self.structure().get_durability()
|
||||
}
|
||||
|
||||
fn get_stress(&self) -> u8 {
|
||||
self.structure().get_stress()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,23 +8,25 @@ pub enum Units {
|
||||
Miner(MinerUnit),
|
||||
}
|
||||
|
||||
impl Units {
|
||||
fn unit(&self) -> &dyn Unit {
|
||||
match self {
|
||||
Self::Miner(m) => m,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Unit for Units {
|
||||
fn get_tag(&self) -> char {
|
||||
match self {
|
||||
Self::Miner(m) => m.get_tag(),
|
||||
}
|
||||
self.unit().get_tag()
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Miner(m) => m.get_name(),
|
||||
}
|
||||
self.unit().get_name()
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
match self {
|
||||
Self::Miner(m) => m.get_owner(),
|
||||
}
|
||||
self.unit().get_owner()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user