diff --git a/CHANGELOG.md b/CHANGELOG.md index cd10a4f9..1f544dcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- Implement `Sum` for `CpuQuantity` and `MemoryQuantity` ([#634]). + +[#634]: https://github.com/stackabletech/operator-rs/pull/634 + ## [0.46.0] - 2023-08-08 ### Changed diff --git a/src/cpu.rs b/src/cpu.rs index 8f780724..005d32e5 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -1,4 +1,5 @@ use std::{ + iter::Sum, ops::{Add, AddAssign, Div, Mul, MulAssign}, str::FromStr, }; @@ -151,6 +152,12 @@ impl MulAssign for CpuQuantity { } } +impl Sum for CpuQuantity { + fn sum>(iter: I) -> Self { + iter.fold(CpuQuantity { millis: 0 }, CpuQuantity::add) + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/memory.rs b/src/memory.rs index 2c7c0733..851f2293 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -356,7 +356,7 @@ impl Add for MemoryQuantity { } } -impl Sum for MemoryQuantity { +impl Sum for MemoryQuantity { fn sum>(iter: I) -> Self { iter.fold( MemoryQuantity {