add IndexFile trait

We want to be able to iterate through digests of index
files, but without always having to distinguish between
dynamic and fixed types, so add a trait we can use as a
trait object.

Unfortunately the iterator needs to yield copies as
iterators cannot yield values with life times when
represented as trait objects (Box<dyn Iterator<Item = ?>>)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2019-02-27 14:32:34 +01:00
parent 5be4065baf
commit 7bc1d72778
4 changed files with 81 additions and 2 deletions

View File

@ -1,6 +1,7 @@
use failure::*;
use crate::tools;
use super::IndexFile;
use super::chunk_stat::*;
use super::chunk_store::*;
use super::chunker::*;
@ -196,6 +197,22 @@ impl DynamicIndexReader {
}
}
impl IndexFile for DynamicIndexReader {
fn index_count(&self) -> usize {
self.index_entries
}
fn index_digest(&self, pos: usize) -> Option<&[u8; 32]> {
if pos >= self.index_entries {
None
} else {
Some(unsafe {
std::mem::transmute(self.chunk_digest(pos).as_ptr())
})
}
}
}
pub struct BufferedDynamicReader {
index: DynamicIndexReader,
archive_size: u64,