From bc1569a46168b74243f9ce0dbfdfe01d2bc0b5ae Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Sat, 28 Jan 2017 02:34:01 -0500 Subject: [PATCH] use IntoIterator to get Ebml iterator --- src/lib.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0e0a32a..bd5fd09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,12 +126,19 @@ pub trait Schema<'a> { } } - fn iter_for<'b: 'a>(self, bytes: &'b[u8]) -> EbmlIterator<'a, Self> - where Self: Sized +} + +pub struct Ebml<'b, S: Schema<'b>>(S, &'b[u8]); + +impl<'b, S: Schema<'b>> IntoIterator for Ebml<'b, S> { + type Item = S::Element; + type IntoIter = EbmlIterator<'b, S>; + + fn into_iter(self) -> EbmlIterator<'b, S> { EbmlIterator { - schema: self, - slice: bytes, + schema: self.0, + slice: self.1, position: 0 } } @@ -285,7 +292,7 @@ mod tests { #[test] fn decode_webm_test1() { - let mut iter = Webm.iter_for(TEST_FILE); + let mut iter = Ebml(Webm, TEST_FILE).into_iter(); // EBML Header assert_eq!(iter.next(), Some(WebmElement::EbmlHead));