diff --git a/src/lib.rs b/src/lib.rs index efbaec1..868b772 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,6 +57,22 @@ impl Sub for Pos { } } +impl std::fmt::Display for Cell { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Cell::Wall => 'X', + Cell::Box => '*', + Cell::Goal(true) => '!', + Cell::Goal(false) => '.', + Cell::None => ' ', + } + ) + } +} + impl std::fmt::Display for Pos { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{} {}", self.0, self.1) @@ -111,17 +127,7 @@ impl std::fmt::Display for Level { if Pos(j, i) == self.player { write!(f, "@")?; } else { - write!( - f, - "{}", - match self[Pos(j, i)] { - Cell::Wall => 'X', - Cell::Box => '*', - Cell::Goal(true) => '!', - Cell::Goal(false) => '.', - Cell::None => ' ', - } - )?; + write!(f, "{}", self[Pos(j, i)])?; } } writeln!(f)?;