Replace util::Range with std::ops::RangeBounds

This commit is contained in:
FreezyLemon 2024-11-01 00:25:42 +01:00 committed by Josh Holmer
parent 764ec831f9
commit 144bf1779b
3 changed files with 15 additions and 47 deletions

View File

@ -1,11 +1,10 @@
use std::ffi::CString; use std::ffi::CString;
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Bound, Deref, DerefMut, RangeBounds};
use super::common::Context; use super::common::Context;
use super::destructor; use super::destructor;
use crate::ffi::*; use crate::ffi::*;
use crate::util::range::Range;
#[cfg(not(feature = "ffmpeg_5_0"))] #[cfg(not(feature = "ffmpeg_5_0"))]
use crate::Codec; use crate::Codec;
use crate::{format, Error, Packet, Stream}; use crate::{format, Error, Packet, Stream};
@ -117,16 +116,21 @@ impl Input {
} }
} }
pub fn seek<R: Range<i64>>(&mut self, ts: i64, range: R) -> Result<(), Error> { pub fn seek<R: RangeBounds<i64>>(&mut self, ts: i64, range: R) -> Result<(), Error> {
unsafe { unsafe {
match avformat_seek_file( let start = match range.start_bound().cloned() {
self.as_mut_ptr(), Bound::Included(i) => i,
-1, Bound::Excluded(i) => i.saturating_add(1),
range.start().cloned().unwrap_or(i64::MIN), Bound::Unbounded => i64::MIN,
ts, };
range.end().cloned().unwrap_or(i64::MAX),
0, let end = match range.end_bound().cloned() {
) { Bound::Included(i) => i,
Bound::Excluded(i) => i.saturating_sub(1),
Bound::Unbounded => i64::MAX,
};
match avformat_seek_file(self.as_mut_ptr(), -1, start, ts, end, 0) {
s if s >= 0 => Ok(()), s if s >= 0 => Ok(()),
e => Err(Error::from(e)), e => Err(Error::from(e)),
} }

View File

@ -12,7 +12,6 @@ pub mod mathematics;
pub mod media; pub mod media;
pub mod option; pub mod option;
pub mod picture; pub mod picture;
pub mod range;
pub mod rational; pub mod rational;
pub mod time; pub mod time;

View File

@ -1,35 +0,0 @@
use std::ops;
pub trait Range<T> {
fn start(&self) -> Option<&T> {
None
}
fn end(&self) -> Option<&T> {
None
}
}
impl<T> Range<T> for ops::Range<T> {
fn start(&self) -> Option<&T> {
Some(&self.start)
}
fn end(&self) -> Option<&T> {
Some(&self.end)
}
}
impl<T> Range<T> for ops::RangeTo<T> {
fn end(&self) -> Option<&T> {
Some(&self.end)
}
}
impl<T> Range<T> for ops::RangeFrom<T> {
fn start(&self) -> Option<&T> {
Some(&self.start)
}
}
impl<T> Range<T> for ops::RangeFull {}