[pbs-devel] [PATCH backup] snapshot_reader: Simplify struct definition
Maximiliano Sandoval
m.sandoval at proxmox.com
Tue Feb 13 11:08:35 CET 2024
Allow us to remove the Clippy exception and makes this code more
readable.
Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
pbs-datastore/src/snapshot_reader.rs | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/pbs-datastore/src/snapshot_reader.rs b/pbs-datastore/src/snapshot_reader.rs
index ec7a48e5..7c626a06 100644
--- a/pbs-datastore/src/snapshot_reader.rs
+++ b/pbs-datastore/src/snapshot_reader.rs
@@ -116,6 +116,18 @@ impl SnapshotReader {
}
}
+struct CurrentIndex {
+ index: Box<dyn IndexFile>,
+ pos: usize,
+ list: Vec<(usize, u64)>,
+}
+
+impl CurrentIndex {
+ fn new(index: Box<dyn IndexFile>, pos: usize, list: Vec<(usize, u64)>) -> Self {
+ CurrentIndex { index, pos, list }
+ }
+}
+
/// Iterates over all chunks used by a backup snapshot
///
/// Note: The iterator returns a `Result`, and the iterator state is
@@ -125,8 +137,7 @@ pub struct SnapshotChunkIterator<'a, F: Fn(&[u8; 32]) -> bool> {
snapshot_reader: &'a SnapshotReader,
todo_list: Vec<String>,
skip_fn: F,
- #[allow(clippy::type_complexity)]
- current_index: Option<(Arc<Box<dyn IndexFile + Send>>, usize, Vec<(usize, u64)>)>,
+ current_index: Option<CurrentIndex>,
}
impl<'a, F: Fn(&[u8; 32]) -> bool> Iterator for SnapshotChunkIterator<'a, F> {
@@ -153,16 +164,16 @@ impl<'a, F: Fn(&[u8; 32]) -> bool> Iterator for SnapshotChunkIterator<'a, F> {
let order =
datastore.get_chunks_in_order(&*index, &self.skip_fn, |_| Ok(()))?;
- self.current_index = Some((Arc::new(index), 0, order));
+ self.current_index = Some(CurrentIndex::new(index, 0, order));
} else {
return Ok(None);
}
}
- let (index, pos, list) = self.current_index.take().unwrap();
+ let CurrentIndex { index, pos, list } = self.current_index.take().unwrap();
if pos < list.len() {
let (real_pos, _) = list[pos];
let digest = *index.index_digest(real_pos).unwrap();
- self.current_index = Some((index, pos + 1, list));
+ self.current_index = Some(CurrentIndex::new(index, pos + 1, list));
return Ok(Some(digest));
} else {
// pop next index
--
2.39.2
More information about the pbs-devel
mailing list