impl Debug for Cells

This commit is contained in:
tali 2022-12-14 14:39:21 -05:00
parent 583b6b64f8
commit 1dcf36ef6f
1 changed files with 21 additions and 0 deletions

View File

@ -154,6 +154,27 @@ impl<'c> Cells<'c> {
}
}
impl core::fmt::Debug for Cells<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let data = self.data();
let (xs, ys) = self.extents();
write!(f, "Cells{{x0={},y0={},data=[", xs.start, ys.start)?;
for (i, &row) in data.iter().enumerate() {
if i > 0 {
write!(f, ",")?;
}
write!(f, "\"")?;
for j in 0..xs.len() {
let occ = row & (1 << j) != 0;
write!(f, "{}", if occ { 'x' } else { '.' })?;
}
write!(f, "\"")?;
}
write!(f, "]}}")?;
Ok(())
}
}
/// Represents the current state of a piece.
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct Piece<S> {