all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 backup 2/5] clippy fixes: use of ok_or followed by a function call
Date: Fri, 16 Jun 2023 10:27:28 +0200	[thread overview]
Message-ID: <20230616082731.45647-3-m.sandoval@proxmox.com> (raw)
In-Reply-To: <20230616082731.45647-1-m.sandoval@proxmox.com>

The function will always be called. This is only bad if it allocates or does some non-trivial amount of work.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
 src/api2/node/services.rs | 4 +++-
 src/api2/tape/drive.rs    | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/api2/node/services.rs b/src/api2/node/services.rs
index 4a73b42d..2786d620 100644
--- a/src/api2/node/services.rs
+++ b/src/api2/node/services.rs
@@ -78,7 +78,9 @@ fn json_service_state(service: &str, status: Value) -> Value {
         let name = status["Name"].as_str().unwrap_or(service);
 
         let state = if status["Type"] == "oneshot" && status["SubState"] == "dead" {
-            status["Result"].as_str().or(status["SubState"].as_str())
+            status["Result"]
+                .as_str()
+                .or_else(|| status["SubState"].as_str())
         } else {
             status["SubState"].as_str()
         }
diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 020dd492..5306e605 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -652,7 +652,7 @@ pub async fn read_label(drive: String, inventorize: Option<bool>) -> Result<Medi
         let mut drive = open_drive(&config, &drive)?;
 
         let (media_id, _key_config) = drive.read_label()?;
-        let media_id = media_id.ok_or(format_err!("Media is empty (no label)."))?;
+        let media_id = media_id.ok_or_else(|| format_err!("Media is empty (no label)."))?;
 
         let label = if let Some(ref set) = media_id.media_set_label {
             let key = &set.encryption_key_fingerprint;
-- 
2.39.2





  parent reply	other threads:[~2023-06-16  8:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16  8:27 [pbs-devel] [PATCH v2 backup 0/5] Clippy fixes Maximiliano Sandoval
2023-06-16  8:27 ` [pbs-devel] [PATCH v2 backup 1/5] clippy fixes: the borrowed expression implements the required traits Maximiliano Sandoval
2023-06-16  8:27 ` Maximiliano Sandoval [this message]
2023-06-16  8:27 ` [pbs-devel] [PATCH v2 backup 3/5] clippy fixes: casting to the same type is unnecessary Maximiliano Sandoval
2023-06-16  8:27 ` [pbs-devel] [PATCH v2 backup 4/5] clippy fixes: Box::new(_) of default value Maximiliano Sandoval
2023-06-16  8:38   ` Daniele Paoni
2023-06-16  8:27 ` [pbs-devel] [PATCH v2 backup 5/5] clippy fixes: deref which would be done by auto-deref Maximiliano Sandoval
2023-06-23 10:07 ` [pbs-devel] applied-series: [PATCH v2 backup 0/5] Clippy fixes 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=20230616082731.45647-3-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 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