use IntoIterator to get Ebml iterator
This commit is contained in:
parent
a23a29bf9b
commit
bc1569a461
1 changed files with 12 additions and 5 deletions
17
src/lib.rs
17
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 {
|
EbmlIterator {
|
||||||
schema: self,
|
schema: self.0,
|
||||||
slice: bytes,
|
slice: self.1,
|
||||||
position: 0
|
position: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,7 +292,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decode_webm_test1() {
|
fn decode_webm_test1() {
|
||||||
let mut iter = Webm.iter_for(TEST_FILE);
|
let mut iter = Ebml(Webm, TEST_FILE).into_iter();
|
||||||
// EBML Header
|
// EBML Header
|
||||||
assert_eq!(iter.next(), Some(WebmElement::EbmlHead));
|
assert_eq!(iter.next(), Some(WebmElement::EbmlHead));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue