1use crate::Error;
2use crate::Log;
3
4pub struct EntryIterator<'a> {
5 log: &'a mut Log,
6 offset: u64,
7}
8
9impl<'a> EntryIterator<'a> {
10 pub fn with_log(log: &'a mut Log) -> Result<Self, Error> {
11 log.flush()?;
12 Ok(EntryIterator { log, offset: 0 })
13 }
14}
15
16impl<'a> std::iter::Iterator for EntryIterator<'a> {
17 type Item = Result<Vec<u8>, Error>;
18
19 fn next(&mut self) -> Option<Self::Item> {
20 if self.log.is_empty() {
21 return None;
22 }
23
24 if self.offset > self.log.last_data_off() {
25 return None;
26 }
27
28 match self.log.read(self.offset) {
29 Ok(chunk) => {
30 self.offset = chunk.next;
31 Some(Ok(chunk.data))
32 }
33 Err(err) => Some(Err(err)),
34 }
35 }
36}