forked from mirrors/gstreamer-rs
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/1366>
This commit is contained in:
parent
2871edeca7
commit
42c028672f
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