From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH backup] snapshot_reader: Simplify struct definition
Date: Tue, 13 Feb 2024 11:08:35 +0100 [thread overview]
Message-ID: <20240213100835.208701-1-m.sandoval@proxmox.com> (raw)
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
reply other threads:[~2024-02-13 10:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240213100835.208701-1-m.sandoval@proxmox.com \
--to=m.sandoval@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox