Tidy cursor iteration module a little
This commit is contained in:
parent
56a7284e32
commit
0e2e5ad48a
1 changed files with 8 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
use futures::Async;
|
use futures::Async;
|
||||||
use ebml::*;
|
use ebml::Error as EbmlError;
|
||||||
|
use ebml::FromEbml;
|
||||||
use webm::*;
|
use webm::*;
|
||||||
|
|
||||||
pub struct EbmlCursor<T> {
|
pub struct EbmlCursor<T> {
|
||||||
|
@ -7,8 +8,8 @@ pub struct EbmlCursor<T> {
|
||||||
position: usize
|
position: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EbmlCursor<T> {
|
impl<S> EbmlCursor<S> {
|
||||||
pub fn new(source: T) -> Self {
|
pub fn new(source: S) -> Self {
|
||||||
EbmlCursor {
|
EbmlCursor {
|
||||||
source,
|
source,
|
||||||
position: 0
|
position: 0
|
||||||
|
@ -20,7 +21,7 @@ impl<'a> Iterator for EbmlCursor<&'a [u8]> {
|
||||||
type Item = WebmElement<'a>;
|
type Item = WebmElement<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<WebmElement<'a>> {
|
fn next(&mut self) -> Option<WebmElement<'a>> {
|
||||||
match Self::Item::decode_element(&self.source[self.position..]) {
|
match Self::Item::decode_element(&self.source.as_ref()[self.position..]) {
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
Ok(None) => None,
|
Ok(None) => None,
|
||||||
Ok(Some((element, element_size))) => {
|
Ok(Some((element, element_size))) => {
|
||||||
|
@ -31,10 +32,10 @@ impl<'a> Iterator for EbmlCursor<&'a [u8]> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, T: AsRef<[u8]>> WebmEventSource for EbmlCursor<T> {
|
impl<'b, S: AsRef<[u8]>> WebmEventSource for EbmlCursor<S> {
|
||||||
type Error = Error;
|
type Error = EbmlError;
|
||||||
|
|
||||||
fn poll_event<'a>(&'a mut self) -> Result<Async<Option<WebmElement<'a>>>, Error> {
|
fn poll_event<'a>(&'a mut self) -> Result<Async<Option<WebmElement<'a>>>, EbmlError> {
|
||||||
match WebmElement::decode_element(&self.source.as_ref()[self.position..]) {
|
match WebmElement::decode_element(&self.source.as_ref()[self.position..]) {
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
Ok(None) => Ok(Async::Ready(None)),
|
Ok(None) => Ok(Async::Ready(None)),
|
||||||
|
|
Loading…
Reference in a new issue