From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D638B90EC7 for ; Tue, 13 Feb 2024 11:09:06 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B371F34258 for ; Tue, 13 Feb 2024 11:08:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 13 Feb 2024 11:08:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 02E9747B31 for ; Tue, 13 Feb 2024 11:08:36 +0100 (CET) From: Maximiliano Sandoval To: pbs-devel@lists.proxmox.com Date: Tue, 13 Feb 2024 11:08:35 +0100 Message-Id: <20240213100835.208701-1-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.019 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH backup] snapshot_reader: Simplify struct definition X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Feb 2024 10:09:06 -0000 Allow us to remove the Clippy exception and makes this code more readable. Signed-off-by: Maximiliano Sandoval --- 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, + pos: usize, + list: Vec<(usize, u64)>, +} + +impl CurrentIndex { + fn new(index: Box, 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, skip_fn: F, - #[allow(clippy::type_complexity)] - current_index: Option<(Arc>, usize, Vec<(usize, u64)>)>, + current_index: Option, } 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