gstreamer: implement Sum on ClockTime

Small convenient helper.
This commit is contained in:
Guillaume Desmottes 2021-10-15 17:00:20 +02:00
parent 67af5ac569
commit 675fe349a7

View file

@ -455,6 +455,13 @@ impl crate::utils::Displayable for ClockTime {
}
}
impl std::iter::Sum for ClockTime {
fn sum<I: Iterator<Item = Self>>(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));
}
}