Strip hash in fmt::Debug and use fmt::Debug for fmt::Display

This commit is contained in:
Eugene P 2019-01-10 13:01:45 +03:00
parent bc7b701de3
commit 94974ec19a

View file

@ -38,16 +38,16 @@ pub struct Hash([u8; 32]);
impl fmt::Debug for Hash {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_hex())
let hash_hex = self.to_hex();
const NUM_SHOW: usize = 12;
write!(f, "{}...", &hash_hex[..NUM_SHOW])
}
}
impl fmt::Display for Hash {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let hash_hex = self.to_hex();
const NUM_SHOW: usize = 12;
write!(f, "{}...", &hash_hex[..NUM_SHOW])
fmt::Debug::fmt(self, f)
}
}