Use another if let in stream parser
This commit is contained in:
parent
884aa37888
commit
4db64df278
1 changed files with 18 additions and 20 deletions
|
@ -1,8 +1,11 @@
|
|||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||
use futures::{TryStreamExt, stream::{Stream, StreamExt}};
|
||||
use futures::{
|
||||
stream::{Stream, StreamExt},
|
||||
TryStreamExt,
|
||||
};
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use crate::ebml::FromEbml;
|
||||
use crate::ebml::{EbmlLayout, FromEbml};
|
||||
use crate::error::WebmetroError;
|
||||
|
||||
pub struct EbmlStreamingParser<S> {
|
||||
|
@ -45,20 +48,16 @@ where
|
|||
cx: &mut Context,
|
||||
) -> Poll<Option<Result<T, WebmetroError>>> {
|
||||
loop {
|
||||
match T::check_space(&self.buffer)? {
|
||||
None => {
|
||||
// need to refill buffer, below
|
||||
}
|
||||
Some(info) => {
|
||||
let mut bytes = self.buffer.split_to(info.element_len).freeze();
|
||||
bytes.advance(info.body_offset);
|
||||
self.borrowed = bytes;
|
||||
return Poll::Ready(Some(
|
||||
T::decode(info.element_id, &self.borrowed).map_err(Into::into),
|
||||
));
|
||||
}
|
||||
if let Some(info) = T::check_space(&self.buffer)? {
|
||||
self.borrowed = self.buffer.split_to(info.element_len).freeze();
|
||||
self.borrowed.advance(info.body_offset);
|
||||
return Poll::Ready(Some(
|
||||
T::decode(info.element_id, &self.borrowed).map_err(Into::into),
|
||||
));
|
||||
}
|
||||
|
||||
// need to refill buffer
|
||||
|
||||
if let Some(limit) = self.buffer_size_limit {
|
||||
if limit <= self.buffer.len() {
|
||||
return Poll::Ready(Some(Err(WebmetroError::ResourcesExceeded)));
|
||||
|
@ -80,9 +79,8 @@ where
|
|||
pub async fn next<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Option<T>, WebmetroError> {
|
||||
loop {
|
||||
if let Some(info) = T::check_space(&self.buffer)? {
|
||||
let mut bytes = self.buffer.split_to(info.element_len).freeze();
|
||||
bytes.advance(info.body_offset);
|
||||
self.borrowed = bytes;
|
||||
self.borrowed = self.buffer.split_to(info.element_len).freeze();
|
||||
self.borrowed.advance(info.body_offset);
|
||||
return Ok(Some(T::decode(info.element_id, &self.borrowed)?));
|
||||
}
|
||||
|
||||
|
@ -193,8 +191,8 @@ mod tests {
|
|||
|
||||
Result::<(), WebmetroError>::Ok(())
|
||||
}
|
||||
.now_or_never()
|
||||
.expect("Test tried to block on I/O")
|
||||
.expect("Parse failed");
|
||||
.now_or_never()
|
||||
.expect("Test tried to block on I/O")
|
||||
.expect("Parse failed");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue