hff_core/read/
chunk_iter.rs

1use super::{ChunkView, Hff};
2use std::fmt::Debug;
3
4/// Iterator over a table's chunks.
5pub struct ChunkIter<'a, T: Debug> {
6    hff: &'a Hff<T>,
7    current: isize,
8    count: usize,
9}
10
11impl<'a, T: Debug> ChunkIter<'a, T> {
12    /// Create a new chunk iterator.
13    pub fn new(hff: &'a Hff<T>, index: usize, count: usize) -> Self {
14        Self {
15            hff,
16            current: index as isize - 1,
17            count,
18        }
19    }
20
21    /// Get the chunk index in the overall table.
22    pub fn index(&self) -> usize {
23        self.current as usize
24    }
25}
26
27impl<'a, T: Debug> Iterator for ChunkIter<'a, T> {
28    type Item = ChunkView<'a, T>;
29
30    fn next(&mut self) -> Option<Self::Item> {
31        if self.count > 0 {
32            self.count -= 1;
33            self.current += 1;
34            Some(ChunkView::new(self.hff, self.current as usize))
35        } else {
36            None
37        }
38    }
39}