[pbs-devel] [PATCH backup 4/4] api: use if-let pattern for error-only handling

Maximiliano Sandoval m.sandoval at proxmox.com
Tue Feb 13 10:53:20 CET 2024


It is more readable than using match. We also inline variables in
eprintln!.

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 src/api2/access/user.rs | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/api2/access/user.rs b/src/api2/access/user.rs
index 118838ce..035c8a57 100644
--- a/src/api2/access/user.rs
+++ b/src/api2/access/user.rs
@@ -391,18 +391,12 @@ pub fn delete_user(userid: Userid, digest: Option<String>) -> Result<(), Error>
         }
     }
 
-    match crate::config::tfa::read().and_then(|mut cfg| {
+    if let Err(err) = crate::config::tfa::read().and_then(|mut cfg| {
         let _: proxmox_tfa::api::NeedsSaving =
             cfg.remove_user(&crate::config::tfa::UserAccess, userid.as_str())?;
         crate::config::tfa::write(&cfg)
     }) {
-        Ok(()) => (),
-        Err(err) => {
-            eprintln!(
-                "error updating TFA config after deleting user {:?}: {}",
-                userid, err
-            );
-        }
+        eprintln!("error updating TFA config after deleting user {userid:?} {err}",);
     }
 
     Ok(())
-- 
2.39.2





More information about the pbs-devel mailing list