Implement Display for ddr::ssq::Row

This makes debugging easier
master
Simon Bruder 2020-06-26 21:11:45 +02:00
parent 60b74c7e97
commit dc27f999c5
No known key found for this signature in database
GPG Key ID: 6F03E0000CC5B62F
1 changed files with 23 additions and 0 deletions

View File

@ -59,6 +59,19 @@ impl Into<Vec<bool>> for PlayerRow {
}
}
impl fmt::Display for PlayerRow {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}{}{}{}",
if self.left { "" } else { " " },
if self.down { "" } else { " " },
if self.up { "" } else { " " },
if self.right { "" } else { " " },
)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Row {
Single(PlayerRow),
@ -79,6 +92,16 @@ impl Into<Vec<bool>> for Row {
}
}
impl fmt::Display for Row {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let player_rows = match self {
Self::Single(player_row) => vec![player_row],
Self::Double(player_row1, player_row2) => vec![player_row1, player_row2],
};
write!(f, "{}", utils::join_display_values(player_rows, " "))
}
}
impl Row {
fn new(byte: u8, players: u8) -> Self {
match players {