From 675fe349a77c4b0842b97a097bca28bb793814af Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 15 Oct 2021 17:00:20 +0200 Subject: [PATCH] gstreamer: implement Sum on ClockTime Small convenient helper. --- gstreamer/src/clock_time.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gstreamer/src/clock_time.rs b/gstreamer/src/clock_time.rs index 0d7c18f33..dab740212 100644 --- a/gstreamer/src/clock_time.rs +++ b/gstreamer/src/clock_time.rs @@ -455,6 +455,13 @@ impl crate::utils::Displayable for ClockTime { } } +impl std::iter::Sum for ClockTime { + fn sum>(iter: I) -> Self { + skip_assert_initialized!(); + iter.fold(ClockTime::ZERO, |a, b| a + b) + } +} + #[cfg(test)] mod tests { use super::*; @@ -815,4 +822,12 @@ mod tests { assert_eq!(format!("{:026}", lots), "0005124095:34:33.709551614"); assert_eq!(format!("{:+026}", lots), "+005124095:34:33.709551614"); } + + #[test] + fn iter_sum() { + let s: ClockTime = vec![ClockTime::from_seconds(1), ClockTime::from_seconds(2)] + .into_iter() + .sum(); + assert_eq!(s, ClockTime::from_seconds(3)); + } }