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),
|
Stone(Stone),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Structures {
|
||||||
|
#[inline]
|
||||||
|
fn structure(&self) -> &dyn Structure {
|
||||||
|
match self {
|
||||||
|
Self::Base(b) => b,
|
||||||
|
Self::Tunnel(t) => t,
|
||||||
|
Self::Stone(s) => s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Structure for Structures {
|
impl Structure for Structures {
|
||||||
fn get_color(&self) -> Color {
|
fn get_color(&self) -> Color {
|
||||||
match self {
|
self.structure().get_color()
|
||||||
Self::Base(b) => b.get_color(),
|
|
||||||
Self::Tunnel(t) => t.get_color(),
|
|
||||||
Self::Stone(s) => s.get_color(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tag(&self) -> char {
|
fn get_tag(&self) -> char {
|
||||||
match self {
|
self.structure().get_tag()
|
||||||
Self::Base(b) => b.get_tag(),
|
|
||||||
Self::Tunnel(t) => t.get_tag(),
|
|
||||||
Self::Stone(s) => s.get_tag(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_level(&self) -> char {
|
fn get_level(&self) -> char {
|
||||||
match self {
|
self.structure().get_level()
|
||||||
Self::Base(b) => b.get_level(),
|
|
||||||
Self::Tunnel(t) => t.get_level(),
|
|
||||||
Self::Stone(s) => s.get_level(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_name(&self) -> &'static str {
|
fn get_name(&self) -> &'static str {
|
||||||
match self {
|
self.structure().get_name()
|
||||||
Self::Base(b) => b.get_name(),
|
|
||||||
Self::Tunnel(t) => t.get_name(),
|
|
||||||
Self::Stone(s) => s.get_name(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_durability(&self) -> u16 {
|
fn get_durability(&self) -> u16 {
|
||||||
match self {
|
self.structure().get_durability()
|
||||||
Self::Base(b) => b.get_durability(),
|
|
||||||
Self::Tunnel(t) => t.get_durability(),
|
|
||||||
Self::Stone(s) => s.get_durability(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_stress(&self) -> u8 {
|
fn get_stress(&self) -> u8 {
|
||||||
match self {
|
self.structure().get_stress()
|
||||||
Self::Base(b) => b.get_stress(),
|
|
||||||
Self::Tunnel(t) => t.get_stress(),
|
|
||||||
Self::Stone(s) => s.get_stress(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,23 +8,25 @@ pub enum Units {
|
|||||||
Miner(MinerUnit),
|
Miner(MinerUnit),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Units {
|
||||||
|
fn unit(&self) -> &dyn Unit {
|
||||||
|
match self {
|
||||||
|
Self::Miner(m) => m,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Unit for Units {
|
impl Unit for Units {
|
||||||
fn get_tag(&self) -> char {
|
fn get_tag(&self) -> char {
|
||||||
match self {
|
self.unit().get_tag()
|
||||||
Self::Miner(m) => m.get_tag(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_name(&self) -> &'static str {
|
fn get_name(&self) -> &'static str {
|
||||||
match self {
|
self.unit().get_name()
|
||||||
Self::Miner(m) => m.get_name(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_owner(&self) -> Players {
|
fn get_owner(&self) -> Players {
|
||||||
match self {
|
self.unit().get_owner()
|
||||||
Self::Miner(m) => m.get_owner(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user