forked from mirrors/gstreamer-rs
gstreamer: implement Sum on ClockTime
Small convenient helper.
This commit is contained in:
parent
67af5ac569
commit
675fe349a7
1 changed files with 15 additions and 0 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue