Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Prefix uint fmt with 0x with alternate flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones committed May 15, 2018
1 parent 8f56606 commit 78e8b0e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rpc/src/v1/types/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ macro_rules! impl_uint {

impl fmt::LowerHex for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:#x}", self.0)
// TODO: remove this once updated to new version of primitives
// including https://github.com/paritytech/primitives/pull/33
// replace with `::core::fmt::LowerHex::fmt(self.0, f)`
if f.alternate() {
write!(f, "0x");
}
write!(f, "{:x}", self.0)
}
}

Expand Down Expand Up @@ -102,19 +108,19 @@ impl_uint!(U64, u64, 1);

impl serde::Serialize for U128 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
serializer.serialize_str(&format!("0x{:x}", self.0))
serializer.serialize_str(&format!("{:#x}", self))
}
}

impl serde::Serialize for U256 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
serializer.serialize_str(&format!("0x{:x}", self.0))
serializer.serialize_str(&format!("{:#x}", self))
}
}

impl serde::Serialize for U64 {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
serializer.serialize_str(&format!("0x{:x}", self.0))
serializer.serialize_str(&format!("{:#x}", self))
}
}

Expand Down

0 comments on commit 78e8b0e

Please sign in to comment.