Skip to content

Commit

Permalink
add Sum<&U128> (#93)
Browse files Browse the repository at this point in the history
* add Sum<&U128>

* format
  • Loading branch information
laizy authored Sep 13, 2020
1 parent 44c1285 commit 0374c21
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ontio-std/src/types/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ impl Sum for U128 {
}
}

impl<'a> Sum<&'a U128> for U128 {
fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self {
iter.fold(U128::new(0), Add::add)
}
}

impl<'a> Add<&'a U128> for U128 {
type Output = U128;

#[track_caller]
fn add(self, rhs: &'a U128) -> Self::Output {
U128(self.0.checked_add(rhs.0).unwrap())
}
}

impl Add<U128> for U128 {
type Output = U128;

Expand Down

0 comments on commit 0374c21

Please sign in to comment.