[board] Clean up the formatting of BitBoards

Use debug_tuple in the fmt::Debug implementation.
Implement fmt::Binary, fmt::UpperHex, and fmt::LowerHex by delegating to u64's version.
This commit is contained in:
Eryn Wells 2023-12-29 15:37:38 -08:00
parent 41421dddbb
commit 808222eef1

View file

@ -47,10 +47,32 @@ impl BitBoard {
}
}
impl fmt::Binary for BitBoard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Delegate to u64's implementation of Binary.
fmt::Binary::fmt(&self.0, f)
}
}
impl fmt::LowerHex for BitBoard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Delegate to u64's implementation of LowerHex.
fmt::LowerHex::fmt(&self.0, f)
}
}
impl fmt::UpperHex for BitBoard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Delegate to u64's implementation of UpperHex.
fmt::UpperHex::fmt(&self.0, f)
}
}
impl fmt::Debug for BitBoard {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let bits = self.0;
write!(f, "BitBoard({bits:064b})")
f.debug_tuple("BitBoard")
.field(&format_args!("{:064b}", self.0))
.finish()
}
}