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 9869F71857 for ; Thu, 9 Jun 2022 12:38:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8CF271AF7C for ; Thu, 9 Jun 2022 12:38:51 +0200 (CEST) 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 id 0C2FF1AF73 for ; Thu, 9 Jun 2022 12:38:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CEA8543A9A for ; Thu, 9 Jun 2022 12:38:50 +0200 (CEST) Date: Thu, 9 Jun 2022 12:38:49 +0200 From: Wolfgang Bumiller To: Hannes Laimer Cc: pbs-devel@lists.proxmox.com Message-ID: <20220609103849.g4rxdo2mpz35froa@wobu-vie.proxmox.com> References: <20220608085154.11271-1-h.laimer@proxmox.com> <20220608085154.11271-3-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220608085154.11271-3-h.laimer@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.324 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs] Subject: Re: [pbs-devel] [PATCH proxmox-backup v2 2/3] disks: use builder pattern for querying disk usage 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: Thu, 09 Jun 2022 10:38:51 -0000 On Wed, Jun 08, 2022 at 08:51:52AM +0000, Hannes Laimer wrote: (...) > diff --git a/src/tools/disks/mod.rs b/src/tools/disks/mod.rs > index ea4c687a..a1436fc3 100644 > --- a/src/tools/disks/mod.rs > +++ b/src/tools/disks/mod.rs > @@ -781,19 +781,77 @@ fn scan_partitions( > Ok(used) > } > > -/// Get disk usage information for a single disk > -pub fn get_disk_usage_info( > - disk: &str, > - no_smart: bool, > - include_partitions: bool, > -) -> Result { > - let mut filter = Vec::new(); > - filter.push(disk.to_string()); > - let mut map = get_disks(Some(filter), no_smart, include_partitions)?; > - if let Some(info) = map.remove(disk) { > - Ok(info) > - } else { > - bail!("failed to get disk usage info - internal error"); // should not happen > +pub struct DisksUsageQuery { Instead of having two types named almost the same with the same parameters apart from disks, I think it would make more sense to just have 2 'query' methods on a single type pass the disk list to one of the query functions. Also, it probably makese sense to use a slice (&[String]) instead of an owned vector anyway in get_disks. > + disks: Option>, > + smart: bool, > + partitions: bool, > +} > + > +impl DisksUsageQuery { > + pub fn new() -> DisksUsageQuery { > + DisksUsageQuery { > + disks: None, > + smart: true, > + partitions: false, > + } > + } > + > + pub fn disks<'a>(&'a mut self, disks: Vec) -> &'a mut DisksUsageQuery { You don't need to name the lifetimes at all here (in any of the methods), and you can use `Self` for the type (`&mut Self`).