all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH backup] snapshot_reader: Simplify struct definition
@ 2024-02-13 10:08 Maximiliano Sandoval
  0 siblings, 0 replies; only message in thread
From: Maximiliano Sandoval @ 2024-02-13 10:08 UTC (permalink / raw)
  To: pbs-devel

Allow us to remove the Clippy exception and makes this code more
readable.

Signed-off-by: Maximiliano Sandoval <m.sandoval@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





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-13 10:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-13 10:08 [pbs-devel] [PATCH backup] snapshot_reader: Simplify struct definition Maximiliano Sandoval

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal