Skip to content

Commit

Permalink
add const new function (#98)
Browse files Browse the repository at this point in the history
* implement debug u256

* add const new function
  • Loading branch information
laizy authored Sep 21, 2020
1 parent ed03b73 commit bbb0fc4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ontio-std/src/types/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ pub struct U256(u256::U256);
impl U256 {
pub const MAX: U256 = U256(u256::U256::MAX);

pub const fn new(value: u128) -> Self {
let mut ret = [0; 4];
ret[0] = value as u64;
ret[1] = (value >> 64) as u64;
U256(u256::U256(ret))
}

pub fn as_u128(&self) -> U128 {
U128(self.0.as_u128())
}
Expand All @@ -278,6 +285,12 @@ impl Display for U256 {
}
}

impl Debug 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 bbb0fc4

Please sign in to comment.