ckb_fixed_hash_core/
std_fmt.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::{H160, H256, H512, H520};

macro_rules! impl_std_fmt {
    ($name:ident, $bytes_size:expr) => {
        impl ::std::fmt::Debug for $name {
            #[inline]
            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                write!(f, stringify!($name))?;
                write!(f, " ( [")?;
                write!(f, " {:#04x}", self.0[0])?;
                for chr in self.0[1..].iter() {
                    write!(f, ", {:#04x}", chr)?;
                }
                write!(f, " ] )")
            }
        }
        impl ::std::fmt::LowerHex for $name {
            #[inline]
            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                let alternate = f.alternate();
                if alternate {
                    write!(f, "0x")?;
                }
                for x in self.0.iter() {
                    write!(f, "{:02x}", x)?;
                }
                Ok(())
            }
        }
        impl ::std::fmt::Display for $name {
            #[inline]
            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                let alternate = f.alternate();
                if alternate {
                    write!(f, "0x")?;
                }
                for x in self.0.iter() {
                    write!(f, "{:02x}", x)?;
                }
                Ok(())
            }
        }
    };
}

impl_std_fmt!(H160, 20);
impl_std_fmt!(H256, 32);
impl_std_fmt!(H512, 64);
impl_std_fmt!(H520, 65);