diff --git a/units/src/block.rs b/units/src/block.rs index 7b407e33c..aabb4c2cc 100644 --- a/units/src/block.rs +++ b/units/src/block.rs @@ -231,6 +231,23 @@ impl ops::SubAssign for BlockInterval { fn sub_assign(&mut self, rhs: BlockInterval) { self.0 = self.to_u32() - rhs.to_u32(); } } +impl core::iter::Sum for BlockInterval { + fn sum>(iter: I) -> Self { + let sum = iter.map(|interval| interval.0).sum(); + BlockInterval::from_u32(sum) + } +} + +impl<'a> core::iter::Sum<&'a BlockInterval> for BlockInterval { + fn sum(iter: I) -> Self + where + I: Iterator, + { + let sum = iter.map(|interval| interval.0).sum(); + BlockInterval::from_u32(sum) + } +} + #[cfg(test)] mod tests { use super::*;