DRY nb_streams
This commit is contained in:
parent
53570d13d7
commit
aa8df7d0d2
@ -1,3 +1,4 @@
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
@ -36,12 +37,17 @@ impl Context {
|
||||
}
|
||||
|
||||
impl Context {
|
||||
#[inline]
|
||||
fn nb_streams(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).nb_streams }
|
||||
}
|
||||
|
||||
pub fn stream<'a, 'b>(&'a self, index: usize) -> Option<Stream<'b>>
|
||||
where
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_streams as usize {
|
||||
if index >= self.nb_streams() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(Stream::wrap(self, index))
|
||||
@ -54,7 +60,7 @@ impl Context {
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_streams as usize {
|
||||
if index >= self.nb_streams() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(StreamMut::wrap(self, index))
|
||||
@ -78,6 +84,7 @@ impl Context {
|
||||
unsafe { (*self.as_ptr()).duration }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn nb_chapters(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).nb_chapters }
|
||||
}
|
||||
@ -87,7 +94,7 @@ impl Context {
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_chapters as usize {
|
||||
if index >= self.nb_chapters() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(Chapter::wrap(self, index))
|
||||
@ -100,7 +107,7 @@ impl Context {
|
||||
'a: 'b,
|
||||
{
|
||||
unsafe {
|
||||
if index >= (*self.as_ptr()).nb_chapters as usize {
|
||||
if index >= self.nb_chapters() as usize {
|
||||
None
|
||||
} else {
|
||||
Some(ChapterMut::wrap(self, index))
|
||||
@ -222,7 +229,7 @@ impl<'a> Iterator for StreamIter<'a> {
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
if self.current >= (*self.context.as_ptr()).nb_streams {
|
||||
if self.current >= self.context.nb_streams() {
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -233,14 +240,12 @@ impl<'a> Iterator for StreamIter<'a> {
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
unsafe {
|
||||
let length = (*self.context.as_ptr()).nb_streams as usize;
|
||||
let length = self.context.nb_streams() as usize;
|
||||
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,13 +269,12 @@ impl<'a> Iterator for StreamIterMut<'a> {
|
||||
type Item = StreamMut<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
if self.current >= self.context.nb_streams() {
|
||||
return None;
|
||||
}
|
||||
self.current += 1;
|
||||
|
||||
unsafe {
|
||||
if self.current >= (*self.context.as_ptr()).nb_streams {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.current += 1;
|
||||
|
||||
Some(StreamMut::wrap(
|
||||
mem::transmute_copy(&self.context),
|
||||
(self.current - 1) as usize,
|
||||
@ -279,14 +283,12 @@ impl<'a> Iterator for StreamIterMut<'a> {
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
unsafe {
|
||||
let length = (*self.context.as_ptr()).nb_streams as usize;
|
||||
let length = self.context.nb_streams() as usize;
|
||||
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
(
|
||||
length - self.current as usize,
|
||||
Some(length - self.current as usize),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user