Merge pull request #37 from yangby-cryptape/hash-lowerhex-alternate
Prefix '0x' for lower hex with alternate flag.
This commit is contained in:
commit
05da6f2d0f
|
@ -133,8 +133,7 @@ macro_rules! construct_hash {
|
||||||
|
|
||||||
impl ::core::fmt::Debug for $from {
|
impl ::core::fmt::Debug for $from {
|
||||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||||
write!(f, "0x")?;
|
write!(f, "{:#x}", self)
|
||||||
::core::fmt::LowerHex::fmt(self, f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,6 +153,9 @@ macro_rules! construct_hash {
|
||||||
|
|
||||||
impl ::core::fmt::LowerHex for $from {
|
impl ::core::fmt::LowerHex for $from {
|
||||||
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||||
|
if f.alternate() {
|
||||||
|
write!(f, "0x");
|
||||||
|
}
|
||||||
for i in &self.0[..] {
|
for i in &self.0[..] {
|
||||||
write!(f, "{:02x}", i)?;
|
write!(f, "{:02x}", i)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ fn should_format_and_debug_correctly() {
|
||||||
assert_eq!(format!("{}", hash), format!("0x{}", display));
|
assert_eq!(format!("{}", hash), format!("0x{}", display));
|
||||||
assert_eq!(format!("{:?}", hash), format!("0x{}", hex));
|
assert_eq!(format!("{:?}", hash), format!("0x{}", hex));
|
||||||
assert_eq!(format!("{:x}", hash), hex);
|
assert_eq!(format!("{:x}", hash), hex);
|
||||||
|
assert_eq!(format!("{:#x}", hash), format!("0x{}", hex));
|
||||||
};
|
};
|
||||||
|
|
||||||
test(0x1, "00000000000000000000000000000001", "0000…0001");
|
test(0x1, "00000000000000000000000000000001", "0000…0001");
|
||||||
|
|
Loading…
Reference in New Issue