Implement fmt::Display for core::Hash

This commit is contained in:
Eugene P 2019-01-10 12:30:10 +03:00
parent 282a5ce980
commit 29fc3e61de
2 changed files with 13 additions and 13 deletions

View file

@ -47,7 +47,18 @@ impl fmt::Debug for Hash {
impl fmt::Display for Hash { impl fmt::Display for Hash {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(self, f) let hash_hex = self.to_hex();
let len = hash_hex.len();
const NUM_SHOW: usize = 8;
let starting = &hash_hex[..NUM_SHOW];
let ending = &hash_hex[(len - NUM_SHOW)..];
write!(f,
"{}...{}",
starting,
ending
)
} }
} }

View file

@ -137,18 +137,7 @@ impl TableViewItem<DiffColumn> for DiffBlock {
match column { match column {
DiffColumn::Height => self.block_height.to_string(), DiffColumn::Height => self.block_height.to_string(),
DiffColumn::Hash => { DiffColumn::Hash => self.block_hash.to_string(),
// Prints part of the hash's hex
let hash_hex = self.block_hash.to_hex();
let len = hash_hex.len();
const NUM_SHOW: usize = 8; // Number of characters to show
format!(
"{}...{}",
&hash_hex[..NUM_SHOW / 2],
&hash_hex[(len - NUM_SHOW)..]
)
}
DiffColumn::PoWType => pow_type, DiffColumn::PoWType => pow_type,
DiffColumn::Difficulty => self.difficulty.to_string(), DiffColumn::Difficulty => self.difficulty.to_string(),
DiffColumn::SecondaryScaling => self.secondary_scaling.to_string(), DiffColumn::SecondaryScaling => self.secondary_scaling.to_string(),