diff options
Diffstat (limited to 'matroska/src/unflatten.rs')
-rw-r--r-- | matroska/src/unflatten.rs | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/matroska/src/unflatten.rs b/matroska/src/unflatten.rs index 71089f4..944d2c7 100644 --- a/matroska/src/unflatten.rs +++ b/matroska/src/unflatten.rs @@ -3,30 +3,23 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2024 metamuffin <metamuffin.org> */ -use crate::{matroska::MatroskaTag, Master}; use crate::Result; - - -pub trait IterWithPos { - type Item; - fn next(&mut self) -> Option<Self::Item>; - fn position(&self) -> usize; -} +use crate::{matroska::MatroskaTag, Master}; pub struct Unflat<'a> { pub item: MatroskaTag, pub children: Option<Unflatten<'a>>, - pub position: usize, + pub position: Option<u64>, } pub struct Unflatten<'a> { - inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>, + inner: &'a mut dyn Iterator<Item = Result<(Option<u64>, MatroskaTag)>>, stop: bool, end: Option<MatroskaTag>, } impl<'a> Unflatten<'a> { - pub fn new(inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>) -> Self { + pub fn new(inner: &'a mut dyn Iterator<Item = Result<(Option<u64>, MatroskaTag)>>) -> Self { Self { inner, stop: false, @@ -34,7 +27,7 @@ impl<'a> Unflatten<'a> { } } pub fn new_with_end( - inner: &'a mut dyn IterWithPos<Item = Result<MatroskaTag>>, + inner: &'a mut dyn Iterator<Item = Result<(Option<u64>, MatroskaTag)>>, start: MatroskaTag, ) -> Self { Self { @@ -47,19 +40,14 @@ impl<'a> Unflatten<'a> { self.stop = true; } - pub fn position(&self) -> usize { - self.inner.position() - } - pub fn n(&mut self) -> Option<Result<Unflat>> { if self.stop { return None; } - let position = self.inner.position(); match self.inner.next() { None => None, Some(Err(e)) => Some(Err(e)), - Some(Ok(item)) => { + Some(Ok((position, item))) => { let master = MatroskaTag::is_master(item.id()).unwrap(); if Some(&item) == self.end.as_ref() { self.stop = true; |