From 11bb7f44123a457282264067fbc155d9c822f65a Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Mon, 2 Apr 2018 13:55:13 -0400 Subject: [PATCH] Fix EBML Source lifetimes, breaking the chunker --- src/ebml.rs | 4 ++-- src/iterator.rs | 2 +- src/webm_stream.rs | 16 +++++----------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/ebml.rs b/src/ebml.rs index a4ff6fe..fee53ab 100644 --- a/src/ebml.rs +++ b/src/ebml.rs @@ -225,7 +225,7 @@ pub trait FromEbml<'b>: Sized { fn should_unwrap(element_id: u64) -> bool; fn decode(element_id: u64, bytes: &'b[u8]) -> Result; - fn decode_element(bytes: &'b[u8]) -> Result, Error> { + fn decode_element<'a: 'b>(bytes: &'a[u8]) -> Result, Error> { match decode_tag(bytes) { Ok(None) => Ok(None), Err(err) => Err(err), @@ -263,7 +263,7 @@ pub trait FromEbml<'b>: Sized { pub trait EbmlEventSource<'a> { type Event: FromEbml<'a>; type Error; - fn poll_event(&mut self) -> Result>, Self::Error>; + fn poll_event(&'a mut self) -> Result>, Self::Error>; } #[cfg(test)] diff --git a/src/iterator.rs b/src/iterator.rs index 7cdd00d..4b3868e 100644 --- a/src/iterator.rs +++ b/src/iterator.rs @@ -41,7 +41,7 @@ impl<'a, T: FromEbml<'a>> EbmlEventSource<'a> for EbmlIterator<'a, T> { type Event = T; type Error = Error; - fn poll_event(&mut self) -> Result>, Error> { + fn poll_event(&'a mut self) -> Result>, Error> { match Self::Event::decode_element(&self.slice[self.position..]) { Err(err) => Err(err), Ok(None) => Ok(Async::Ready(None)), diff --git a/src/webm_stream.rs b/src/webm_stream.rs index 5e0996d..f23eb54 100644 --- a/src/webm_stream.rs +++ b/src/webm_stream.rs @@ -47,7 +47,7 @@ impl, S: Stream> WebmStream { } } - pub fn poll_event2<'a>(&'a mut self) -> Result>>, ParsingError> { + pub fn poll_event<'a>(&'a mut self) -> Result>>, ParsingError> { // release buffer from previous event self.buffer.advance(self.last_read); self.last_read = 0; @@ -71,20 +71,14 @@ impl, S: Stream> WebmStream { } } -/*fn umm<'a, I: AsRef<[u8]>, S: Stream>(webm_stream: &'a mut WebmStream) - -> Result>>, ParsingError> -{ - return webmStream.poll_event(); -}*/ - -/*impl<'a, I: AsRef<[u8]>, S: Stream> EbmlEventSource<'a> for WebmStream { +impl<'a, I: AsRef<[u8]>, S: Stream> EbmlEventSource<'a> for WebmStream { type Event = WebmElement<'a>; type Error = ParsingError; - fn poll_event(&'a mut self) -> Result>>, Self::Error> { - return self.poll_event2(); + fn poll_event(&'a mut self) -> Result>, Self::Error> { + return WebmStream::poll_event(&mut self); } -}*/ +} #[cfg(test)] mod tests {