diff options
author | metamuffin <metamuffin@disroot.org> | 2023-01-25 07:42:27 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-01-25 07:42:27 +0100 |
commit | 814896238c9b3928709f27606816ab6de60abdf3 (patch) | |
tree | 8134ed5213cf41f907f2af68ad9c8df245a937bd /matroska/src/unflatten.rs | |
parent | 4529d07cc3f2f86a9dbb0d4802875a81d5c4c495 (diff) | |
download | jellything-814896238c9b3928709f27606816ab6de60abdf3.tar jellything-814896238c9b3928709f27606816ab6de60abdf3.tar.bz2 jellything-814896238c9b3928709f27606816ab6de60abdf3.tar.zst |
generate seek index
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; |