homework: use hash map and implement Debug trait

This commit is contained in:
7 changed files with 51 additions and 36 deletions

View File

@@ -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)]