impl Debug for Mat

This commit is contained in:
tali 2022-12-16 10:16:53 -05:00
parent 1eee852191
commit aee42c7ddf
1 changed files with 20 additions and 1 deletions

View File

@ -36,11 +36,13 @@ impl Mat {
pub const EMPTY: &'static Self = Self::new(&[]);
#[inline]
const fn data(&self) -> &[u16] {
unsafe { core::mem::transmute(self) }
&self.0
}
/// Returns the number of columns in the matrix. This always returns `COLUMNS`.
#[inline]
pub const fn cols(&self) -> i16 {
COLUMNS
}
@ -73,6 +75,23 @@ impl Mat {
}
}
impl core::fmt::Debug for Mat {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "mat!{{")?;
let mut sep = "";
for y in (0..self.rows()).rev() {
write!(f, "{sep}\"")?;
for x in 0..self.cols() {
let occ = self.get(x, y);
f.write_str(if occ { "x" } else { "." })?;
}
write!(f, "\"")?;
sep = ";";
}
write!(f, "}}")
}
}
#[cfg(any(feature = "ascii", test))]
#[doc(hidden)]
pub mod __ascii {