refactor: use Rational::non_zero instead of manual comparisons

This commit is contained in:
tilpner
2023-08-29 16:09:33 +02:00
parent 23dde387b7
commit df08039eeb
4 changed files with 6 additions and 39 deletions
+2 -16
View File
@@ -136,26 +136,12 @@ impl Context {
}
pub fn frame_rate(&self) -> Option<Rational> {
unsafe {
let fr = Rational::from((*self.as_ptr()).framerate);
if fr == Rational(0, 1) {
None
}
else {
Some(fr)
}
}
unsafe { Rational::from((*self.as_ptr()).framerate).non_zero() }
}
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
unsafe {
if let Some(value) = value {
(*self.as_mut_ptr()).framerate = value.into().into();
}
else {
(*self.as_mut_ptr()).framerate.num = 0;
(*self.as_mut_ptr()).framerate.den = 1;
}
(*self.as_mut_ptr()).framerate = value.map(Into::into).unwrap_or(Rational::ZERO).into();
}
}
}
+1 -10
View File
@@ -82,16 +82,7 @@ impl Opened {
}
pub fn frame_rate(&self) -> Option<Rational> {
unsafe {
let value = (*self.as_ptr()).framerate;
if value == (AVRational { num: 0, den: 1 }) {
None
}
else {
Some(Rational::from(value))
}
}
unsafe { Rational::from((*self.as_ptr()).framerate).non_zero() }
}
pub fn flush(&mut self) {
+2 -7
View File
@@ -61,14 +61,9 @@ impl Iterator for RateIter {
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
if (*self.ptr).num == 0 && (*self.ptr).den == 0 {
return None;
}
let rate = (*self.ptr).into();
let rate = Rational::from(*self.ptr).non_zero();
self.ptr = self.ptr.offset(1);
Some(rate)
rate
}
}
}
+1 -6
View File
@@ -107,12 +107,7 @@ impl<'a> Stream<'a> {
ptr::null_mut(),
));
if r == Rational(0, 1) {
None
}
else {
Some(r)
}
r.non_zero()
}
}