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:
@ -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,
|
||||
|
Reference in New Issue
Block a user