Tidy Stream extension trait impl

This commit is contained in:
Tangent 2018-04-07 01:09:17 -04:00
parent 9ca384f9da
commit b7ee425905
4 changed files with 12 additions and 19 deletions

View file

@ -18,12 +18,8 @@ pub struct EbmlStreamingParser<S> {
last_read: usize
}
pub trait StreamEbml<I: AsRef<[u8]>, S: Stream<Item = I>> {
fn parse_ebml(self) -> EbmlStreamingParser<S>;
}
impl<I: AsRef<[u8]>, S: Stream<Item = I>> StreamEbml<I, S> for S {
fn parse_ebml(self) -> EbmlStreamingParser<S> {
pub trait StreamEbml where Self: Sized + Stream, Self::Item: AsRef<[u8]> {
fn parse_ebml(self) -> EbmlStreamingParser<Self> {
EbmlStreamingParser {
stream: self,
buffer: BytesMut::new(),
@ -32,6 +28,8 @@ impl<I: AsRef<[u8]>, S: Stream<Item = I>> StreamEbml<I, S> for S {
}
}
impl<I: AsRef<[u8]>, S: Stream<Item = I>> StreamEbml for S {}
impl<I: AsRef<[u8]>, S: Stream<Item = I>> EbmlStreamingParser<S> {
pub fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result<Async<Option<T>>, ParsingError<S::Error>> {
// release buffer from previous event