all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Hannes Laimer <h.laimer@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox-backup v2 2/3] disks: use builder pattern for querying disk usage
Date: Thu, 9 Jun 2022 12:38:49 +0200	[thread overview]
Message-ID: <20220609103849.g4rxdo2mpz35froa@wobu-vie.proxmox.com> (raw)
In-Reply-To: <20220608085154.11271-3-h.laimer@proxmox.com>

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<DiskUsageInfo, Error> {
> -    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<Vec<String>>,
> +    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<String>) -> &'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`).




  reply	other threads:[~2022-06-09 10:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08  8:51 [pbs-devel] [PATCH proxmox-backup/proxmox-widget-toolkit v2 0/4] add partitions to disks/list endpoint Hannes Laimer
2022-06-08  8:51 ` [pbs-devel] [PATCH proxmox-backup v2 1/3] api2: disks endpoint return partitions Hannes Laimer
2022-06-08  8:51 ` [pbs-devel] [PATCH proxmox-backup v2 2/3] disks: use builder pattern for querying disk usage Hannes Laimer
2022-06-09 10:38   ` Wolfgang Bumiller [this message]
2022-06-15  6:07     ` [pbs-devel] [PATCH proxmox-backup v3 " Hannes Laimer
2022-06-15  6:17     ` Hannes Laimer
2022-06-08  8:51 ` [pbs-devel] [PATCH proxmox-backup v2 3/3] ui: disks: show partitions by default Hannes Laimer
2022-06-08  8:51 ` [pbs-devel] [PATCH proxmox-widget-toolkit v2 1/1] ui: DiskLisk: handle partition data from PBS backend Hannes Laimer
2022-06-15  8:58   ` [pbs-devel] applied: " Wolfgang Bumiller
2022-06-15  7:58 ` [pbs-devel] [PATCH proxmox-backup/proxmox-widget-toolkit v2 0/4] add partitions to disks/list endpoint Wolfgang Bumiller
2022-06-15  8:08   ` Dominik Csapak
2022-06-15  8:10     ` Hannes Laimer
2022-06-15  8:17       ` Wolfgang Bumiller
2022-06-15  9:09 ` [pbs-devel] applied-series: [PATCH proxmox-backup/proxmox-widget-toolkit v2 0/4] add partitions to disks/list endpointg Wolfgang Bumiller

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=20220609103849.g4rxdo2mpz35froa@wobu-vie.proxmox.com \
    --to=w.bumiller@proxmox.com \
    --cc=h.laimer@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 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