1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::{ChunkView, Hff};

/// Iterator over a table's chunks.
pub struct ChunkIter<'a> {
    hff: &'a Hff,
    current: isize,
    count: usize,
}

impl<'a> ChunkIter<'a> {
    /// Create a new chunk iterator.
    pub fn new(hff: &'a Hff, index: usize, count: usize) -> Self {
        Self {
            hff,
            current: index as isize - 1,
            count,
        }
    }
}

impl<'a> Iterator for ChunkIter<'a> {
    type Item = ChunkView<'a>;

    fn next(&mut self) -> Option<Self::Item> {
        if self.count > 0 {
            self.count -= 1;
            self.current += 1;
            Some(ChunkView::new(self.hff, self.current as usize))
        } else {
            None
        }
    }
}