homework: extract print_status into a separate trait

This commit is contained in:
7 changed files with 22 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
use crate::PrintStatus;
use std::fmt::Display;
#[derive(Debug)]
@@ -17,10 +18,6 @@ impl Device {
}
}
}
pub fn print_status(&self) {
println!("{}", self.display());
}
}
impl From<super::Thermometer> for Device {
@@ -35,6 +32,12 @@ impl From<super::PowerSocket> for Device {
}
}
impl PrintStatus for Device {
fn print_status(&self) {
println!("{}", self.display());
}
}
#[cfg(test)]
mod tests {
use super::*;