Nicer display output for hash types.

This commit is contained in:
Gav Wood 2016-01-14 12:27:41 +01:00
parent 787a119f12
commit 1c89b9732d
2 changed files with 8 additions and 1 deletions

View File

@ -206,7 +206,10 @@ macro_rules! impl_hash {
}
impl fmt::Display for $from {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
(self as &fmt::Debug).fmt(f)
for i in self.0[0..3].iter() {
try!(write!(f, "{:02x}", i));
}
write!(f, "…{:02x}", self.0.last().unwrap())
}
}

View File

@ -35,6 +35,10 @@ pub fn h256_from_json(json: &Json) -> H256 {
}
}
pub fn vec_h256_from_json(json: &Json) -> Vec<H256> {
json.as_array().unwrap().iter().map(&h256_from_json).collect()
}
pub fn u256_from_str(s: &str) -> U256 {
if s.len() >= 2 && &s[0..2] == "0x" {
U256::from_str(&s[2..]).unwrap_or(U256::from(0))