Skip to content

Commit c4a1ee6

Browse files
committed
impl Sum trait
1 parent d889d90 commit c4a1ee6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/v1/value/value_utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use num_bigint::BigInt;
33
use num_traits::Zero;
44
use std::{
55
collections::BTreeMap,
6+
iter::Sum,
67
ops::{Add, Mul, Neg, Not, Sub},
78
};
89

@@ -198,3 +199,15 @@ impl Mul<&BigInt> for &Value {
198199
)
199200
}
200201
}
202+
203+
impl Sum<Value> for Value {
204+
fn sum<I: Iterator<Item = Value>>(iter: I) -> Self {
205+
iter.fold(Zero::zero(), Add::add)
206+
}
207+
}
208+
209+
impl<'a> Sum<&'a Value> for Value {
210+
fn sum<I: Iterator<Item = &'a Value>>(iter: I) -> Self {
211+
iter.fold(Zero::zero(), Add::add)
212+
}
213+
}

0 commit comments

Comments
 (0)