Replace default fmt::Display on core::Hash (#2325)

* Print block hash in TUI partially
* Implement fmt::Display for core::Hash
* Show first 12 digits of Hash
* Show full hex string of hash in fmt::Debug for core::Hash
* Strip hash in fmt::Debug and use fmt::Debug for fmt::Display
This commit is contained in:
Ignotus Peverell 2019-01-10 12:13:23 -08:00 committed by GitHub
commit 27b4e2145a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,10 +38,10 @@ pub struct Hash([u8; 32]);
impl fmt::Debug for Hash {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for i in self.0[..4].iter() {
write!(f, "{:02x}", i)?;
}
Ok(())
let hash_hex = self.to_hex();
const NUM_SHOW: usize = 12;
write!(f, "{}...", &hash_hex[..NUM_SHOW])
}
}