Make the buffer generic

This commit is contained in:
Tangent 128 2018-04-03 22:06:09 -04:00
parent c92273625e
commit 413f7759c6

View file

@ -26,13 +26,13 @@ impl<I: AsRef<[u8]>, S: Stream<Item = I>> WebmBuffer<S> {
} }
} }
pub fn poll_event<'a>(&'a mut self) -> Result<Async<Option<WebmElement<'a>>>, ParsingError<S::Error>> { pub fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, ParsingError<S::Error>> {
// release buffer from previous event // release buffer from previous event
self.buffer.advance(self.last_read); self.buffer.advance(self.last_read);
self.last_read = 0; self.last_read = 0;
loop { loop {
match WebmElement::check_space(&self.buffer) { match T::check_space(&self.buffer) {
Err(err) => { Err(err) => {
return Err(ParsingError::EbmlError(err)) return Err(ParsingError::EbmlError(err))
}, },
@ -40,7 +40,7 @@ impl<I: AsRef<[u8]>, S: Stream<Item = I>> WebmBuffer<S> {
// need to refill buffer, below // need to refill buffer, below
}, },
Ok(Some(_)) => { Ok(Some(_)) => {
return match WebmElement::decode_element(&self.buffer) { return match T::decode_element(&self.buffer) {
Err(err) => { Err(err) => {
Err(ParsingError::EbmlError(err)) Err(ParsingError::EbmlError(err))
}, },