homework: use hash map and implement Debug trait
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Device {
|
||||
Thermometer(super::Thermometer),
|
||||
PowerSocket(super::PowerSocket),
|
||||
@@ -20,6 +21,13 @@ impl Device {
|
||||
pub fn print_status(&self) {
|
||||
println!("{}", self.display());
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> &str {
|
||||
match self {
|
||||
Device::Thermometer(thermometer) => thermometer.get_name(),
|
||||
Device::PowerSocket(power_socket) => power_socket.get_name(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user