mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 00:26:31 +00:00
gstreamer: formatted values: Implement ClockTime::absdiff()
and on related types
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/494 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1364>
This commit is contained in:
parent
fddeacc358
commit
34fee6b691
2 changed files with 22 additions and 0 deletions
|
@ -1801,4 +1801,15 @@ mod tests {
|
|||
let neg = Signed::<ClockTime>::from_seconds_f64(-5.0);
|
||||
assert!(neg.is_negative());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn absdiff() {
|
||||
let t1 = ClockTime::from_seconds(10);
|
||||
let t2 = ClockTime::from_seconds(4);
|
||||
|
||||
let d = ClockTime::from_seconds(6);
|
||||
|
||||
assert_eq!(t1.absdiff(t2), d);
|
||||
assert_eq!(t2.absdiff(t1), d);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,6 +93,17 @@ macro_rules! impl_non_trait_op_same(
|
|||
pub const fn wrapping_sub(self, rhs: Self) -> Self {
|
||||
self.overflowing_sub(rhs).0
|
||||
}
|
||||
|
||||
#[must_use = "this returns the result of the operation, without modifying the original"]
|
||||
#[inline]
|
||||
pub fn absdiff(self, rhs: Self) -> Self {
|
||||
if self > rhs {
|
||||
self - rhs
|
||||
} else {
|
||||
rhs - self
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue