From eda2e4f7beb5db500f4a64218f496074ae213a9c Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Mon, 21 Oct 2019 01:20:14 -0400 Subject: [PATCH] Remove EbmlEventSource trait in favor of concrete EbmlStreamingParser --- src/chunk.rs | 21 ++++++++++++--------- src/ebml.rs | 6 ------ src/stream_parser.rs | 12 +----------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/chunk.rs b/src/chunk.rs index 477e204..2813ce3 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -1,10 +1,10 @@ -use bytes::Bytes; +use bytes::{Buf, Bytes}; use futures::{Async, Stream}; use std::{ io::Cursor, mem }; -use crate::ebml::EbmlEventSource; +use crate::stream_parser::EbmlStreamingParser; use crate::error::WebmetroError; use crate::webm::*; @@ -103,7 +103,7 @@ enum ChunkerState { } pub struct WebmChunker { - source: S, + source: EbmlStreamingParser, buffer_size_limit: Option, state: ChunkerState } @@ -128,8 +128,7 @@ fn encode(element: WebmElement, buffer: &mut Cursor>, limit: Option Stream for WebmChunker -where S::Error: Into +impl> Stream for WebmChunker { type Item = Chunk; type Error = WebmetroError; @@ -266,8 +265,14 @@ where S::Error: Into } } -pub trait WebmStream where Self: Sized + EbmlEventSource { - fn chunk_webm(self) -> WebmChunker { +pub trait WebmStream { + type Stream; + fn chunk_webm(self) -> WebmChunker; +} + +impl WebmStream for EbmlStreamingParser { + type Stream = S; + fn chunk_webm(self) -> WebmChunker { WebmChunker { source: self, buffer_size_limit: None, @@ -276,8 +281,6 @@ pub trait WebmStream where Self: Sized + EbmlEventSource { } } -impl WebmStream for T {} - #[cfg(test)] mod tests { diff --git a/src/ebml.rs b/src/ebml.rs index 8844a5f..7eae90c 100644 --- a/src/ebml.rs +++ b/src/ebml.rs @@ -1,7 +1,6 @@ use bytes::{BigEndian, ByteOrder, BufMut}; use custom_error::custom_error; use std::io::{Cursor, Error as IoError, ErrorKind, Result as IoResult, Write, Seek, SeekFrom}; -use futures::Async; pub const EBML_HEAD_ID: u64 = 0x0A45DFA3; pub const DOC_TYPE_ID: u64 = 0x0282; @@ -261,11 +260,6 @@ pub trait FromEbml<'a>: Sized { } } -pub trait EbmlEventSource { - type Error; - fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result>, Self::Error>; -} - #[cfg(test)] mod tests { use bytes::{BytesMut}; diff --git a/src/stream_parser.rs b/src/stream_parser.rs index a4a02fa..b0bfe20 100644 --- a/src/stream_parser.rs +++ b/src/stream_parser.rs @@ -1,7 +1,7 @@ use bytes::{Buf, BufMut, Bytes, BytesMut}; use futures::{stream::Stream, Async}; -use crate::ebml::{EbmlEventSource, FromEbml}; +use crate::ebml::FromEbml; use crate::error::WebmetroError; pub struct EbmlStreamingParser { @@ -76,16 +76,6 @@ impl> EbmlStreamingParser } } -impl> EbmlEventSource - for EbmlStreamingParser -{ - type Error = WebmetroError; - - fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result>, WebmetroError> { - return EbmlStreamingParser::poll_event(self); - } -} - #[cfg(test)] mod tests { use bytes::IntoBuf;