Skip to content

Commit

Permalink
implement display for u256
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy committed Sep 21, 2020
1 parent 0a6a4e1 commit b056fd5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ontio-std/src/types/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,19 @@ impl U256 {
U256(u256::U256::from_little_endian(slice))
}

pub fn to_le_bytes(self) -> [u8; 32] {
pub fn to_le_bytes(&self) -> [u8; 32] {
let mut buf = [0; 32];
self.0.to_little_endian(&mut buf);
buf
}
}

impl Display for U256 {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", self.0)
}
}

impl From<u128> for U256 {
fn from(val: u128) -> Self {
Self(From::from(val))
Expand Down

0 comments on commit b056fd5

Please sign in to comment.