diff options
Diffstat (limited to 'matroska/src/unflatten.rs')
-rw-r--r-- | matroska/src/unflatten.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/matroska/src/unflatten.rs b/matroska/src/unflatten.rs index 5e0ba31..663eebc 100644 --- a/matroska/src/unflatten.rs +++ b/matroska/src/unflatten.rs @@ -6,19 +6,25 @@ use crate::{matroska::MatroskaTag, Master}; use anyhow::Result; +pub trait IterWithPos { + type Item; + fn next(&mut self) -> Option<Self::Item>; + fn position(&self) -> usize; +} + pub struct Unflat<'a> { pub item: MatroskaTag, pub children: Option<Unflatten<'a>>, } pub struct Unflatten<'a> { - inner: &'a mut dyn Iterator<Item = Result<MatroskaTag>>, + inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>, stop: bool, end: Option<MatroskaTag>, } impl<'a> Unflatten<'a> { - pub fn new(inner: &'a mut dyn Iterator<Item = Result<MatroskaTag>>) -> Self { + pub fn new(inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>) -> Self { Self { inner, stop: false, @@ -26,7 +32,7 @@ impl<'a> Unflatten<'a> { } } pub fn new_with_end( - inner: &'a mut dyn Iterator<Item = Result<MatroskaTag>>, + inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>, start: MatroskaTag, ) -> Self { Self { @@ -36,6 +42,10 @@ impl<'a> Unflatten<'a> { } } + pub fn position(&self) -> usize { + self.inner.position() + } + pub fn next(&mut self) -> Option<Result<Unflat>> { if self.stop { return None; |