From 2db227c5f90e89043bc1f88d4bf64f8725238ef5 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Tue, 3 Apr 2018 23:38:31 -0400 Subject: [PATCH] Cleanup, use EbmlSlice as name --- src/ebml.rs | 5 ----- src/iterator.rs | 28 +++++++++------------------- src/webm.rs | 6 +++--- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/ebml.rs b/src/ebml.rs index d780b89..f849dab 100644 --- a/src/ebml.rs +++ b/src/ebml.rs @@ -214,11 +214,6 @@ pub fn encode_integer(tag: u64, value: u64, output: &mut T) -> IoResul output.write_all(&buffer.get_ref()[..]) } -#[derive(Debug, PartialEq)] -pub struct Ebml { - pub source: Source -} - pub trait FromEbml<'a>: Sized { /// Indicates if this tag's contents should be treated as a blob, /// or if the tag header should be reported as an event and with further diff --git a/src/iterator.rs b/src/iterator.rs index d8a6850..0dfa72e 100644 --- a/src/iterator.rs +++ b/src/iterator.rs @@ -4,23 +4,13 @@ use ebml::EbmlEventSource; use ebml::FromEbml; use webm::WebmElement; -pub struct EbmlCursor<'a> { - source: &'a [u8] -} +pub struct EbmlSlice<'a>(pub &'a [u8]); -impl<'a> EbmlCursor<'a> { - pub fn new(source: &'a [u8]) -> Self { - EbmlCursor { - source - } - } -} - -impl<'a> Iterator for EbmlCursor<'a> { +impl<'a> Iterator for EbmlSlice<'a> { type Item = WebmElement<'a>; fn next(&mut self) -> Option> { - match WebmElement::check_space(self.source) { + match WebmElement::check_space(self.0) { Err(err) => { None }, @@ -28,8 +18,8 @@ impl<'a> Iterator for EbmlCursor<'a> { None }, Ok(Some(element_size)) => { - let (element_data, rest) = self.source.split_at(element_size); - self.source = rest; + let (element_data, rest) = self.0.split_at(element_size); + self.0 = rest; match WebmElement::decode_element(element_data) { Err(err) => { None @@ -47,11 +37,11 @@ impl<'a> Iterator for EbmlCursor<'a> { } } -impl<'b> EbmlEventSource for EbmlCursor<'b> { +impl<'b> EbmlEventSource for EbmlSlice<'b> { type Error = EbmlError; fn poll_event<'a, T: FromEbml<'a>>(&'a mut self) -> Result>, EbmlError> { - match T::check_space(self.source) { + match T::check_space(self.0) { Err(err) => { Err(err) }, @@ -59,8 +49,8 @@ impl<'b> EbmlEventSource for EbmlCursor<'b> { Ok(None) }, Ok(Some(element_size)) => { - let (element_data, rest) = self.source.split_at(element_size); - self.source = rest; + let (element_data, rest) = self.0.split_at(element_size); + self.0 = rest; match T::decode_element(element_data) { Err(err) => { Err(err) diff --git a/src/webm.rs b/src/webm.rs index 50d76cd..bdc1864 100644 --- a/src/webm.rs +++ b/src/webm.rs @@ -1,7 +1,7 @@ use std::io::{Cursor, Error as IoError, ErrorKind, Result as IoResult, Write, Seek}; use bytes::{BigEndian, BufMut, ByteOrder}; use ebml::*; -use iterator::EbmlCursor; +use iterator::EbmlSlice; const SEGMENT_ID: u64 = 0x08538067; const SEEK_HEAD_ID: u64 = 0x014D9B74; @@ -12,8 +12,8 @@ const CLUSTER_ID: u64 = 0x0F43B675; const TIMECODE_ID: u64 = 0x67; const SIMPLE_BLOCK_ID: u64 = 0x23; -pub fn parse_webm<'a, T: AsRef<[u8]> + ?Sized>(source: &'a T) -> EbmlCursor<'a> { - EbmlCursor::new(source.as_ref()) +pub fn parse_webm<'a, T: AsRef<[u8]> + ?Sized>(source: &'a T) -> EbmlSlice<'a> { + EbmlSlice(source.as_ref()) } #[derive(Debug, PartialEq, Copy, Clone)]