public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Shannon Sterz" <s.sterz@proxmox.com>
To: "Proxmox Backup Server development discussion"
	<pbs-devel@lists.proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox 02/18] use contains_key instead of .get().is_{some, none}()
Date: Wed, 26 Jun 2024 13:16:17 +0200	[thread overview]
Message-ID: <D29WMWWGKLD4.2RL0UQ9TSHNK7@proxmox.com> (raw)
In-Reply-To: <20240626104514.384718-2-m.sandoval@proxmox.com>

On Wed Jun 26, 2024 at 12:44 PM CEST, Maximiliano Sandoval wrote:
> Fixes the clippy lints:
>
> warning: unnecessary use of `get("lo").is_none()`
>    --> proxmox-network-api/src/config/parser.rs:603:30
>     |
> 603 |         if config.interfaces.get("lo").is_none() {
>     |            ------------------^^^^^^^^^^^^^^^^^^^
>     |            |
>     |            help: replace it with: `!config.interfaces.contains_key("lo")`
>     |
>     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
>     = note: `#[warn(clippy::unnecessary_get_then_check)]` on by default
>
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
>  proxmox-access-control/src/acl.rs        | 6 +++---
>  proxmox-acme-api/src/plugin_config.rs    | 2 +-
>  proxmox-network-api/src/config/parser.rs | 2 +-
>  proxmox-section-config/src/lib.rs        | 2 +-
>  4 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/proxmox-access-control/src/acl.rs b/proxmox-access-control/src/acl.rs
> index b6b7b400..af68159c 100644
> --- a/proxmox-access-control/src/acl.rs
> +++ b/proxmox-access-control/src/acl.rs
> @@ -973,14 +973,14 @@ mod test {
>              let node = tree.find_node(path);
>              assert!(node.is_some());
>              if let Some(node) = node {
> -                assert!(node.users.get(&user1).is_none());
> +                assert!(!node.users.contains_key(&user1));
>              }
>          }
>          for path in &user2_paths {
>              let node = tree.find_node(path);
>              assert!(node.is_some());
>              if let Some(node) = node {
> -                assert!(node.users.get(&user2).is_some());
> +                assert!(node.users.contains_key(&user2));
>              }
>          }
>
> @@ -990,7 +990,7 @@ mod test {
>              let node = tree.find_node(path);
>              assert!(node.is_some());
>              if let Some(node) = node {
> -                assert!(node.users.get(&user2).is_none());
> +                assert!(!node.users.contains_key(&user2));
>              }
>          }
>
> diff --git a/proxmox-acme-api/src/plugin_config.rs b/proxmox-acme-api/src/plugin_config.rs
> index 4ebd0315..e0836f50 100644
> --- a/proxmox-acme-api/src/plugin_config.rs
> +++ b/proxmox-acme-api/src/plugin_config.rs
> @@ -67,7 +67,7 @@ pub(crate) fn plugin_config() -> Result<(PluginData, ConfigDigest), Error> {
>      let digest = ConfigDigest::from_slice(content.as_bytes());
>      let mut data = CONFIG.parse(plugin_cfg_filename, &content)?;
>
> -    if data.sections.get("standalone").is_none() {
> +    if data.sections.contains_key("standalone") {

you missed a "!" here `contains_key` returns `true` when the key is
there, `is_none` is true when it isn't.

>          let standalone = StandalonePlugin::default();
>          data.set_data("standalone", "standalone", &standalone)
>              .unwrap();
> diff --git a/proxmox-network-api/src/config/parser.rs b/proxmox-network-api/src/config/parser.rs
> index dc8e2d0a..2d20b9e4 100644
> --- a/proxmox-network-api/src/config/parser.rs
> +++ b/proxmox-network-api/src/config/parser.rs
> @@ -600,7 +600,7 @@ impl<R: BufRead> NetworkParser<R> {
>              }
>          }
>
> -        if config.interfaces.get("lo").is_none() {
> +        if !config.interfaces.contains_key("lo") {
>              let mut interface = Interface::new(String::from("lo"));
>              set_method_v4(&mut interface, NetworkConfigMethod::Loopback)?;
>              interface.interface_type = NetworkInterfaceType::Loopback;
> diff --git a/proxmox-section-config/src/lib.rs b/proxmox-section-config/src/lib.rs
> index 526ee8f1..e36d8995 100644
> --- a/proxmox-section-config/src/lib.rs
> +++ b/proxmox-section-config/src/lib.rs
> @@ -322,7 +322,7 @@ impl SectionConfig {
>          let mut done = HashSet::new();
>
>          for section_id in &config.order {
> -            if config.sections.get(section_id).is_none() {
> +            if !config.sections.contains_key(section_id) {
>                  continue;
>              };
>              list.push(section_id);



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel




  reply	other threads:[~2024-06-26 11:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-26 10:44 [pbs-devel] [PATCH proxmox 01/18] use unwrap_or_default instead of unwrap_or(Vec::new) Maximiliano Sandoval
2024-06-26 10:44 ` [pbs-devel] [PATCH proxmox 02/18] use contains_key instead of .get().is_{some, none}() Maximiliano Sandoval
2024-06-26 11:16   ` Shannon Sterz [this message]
2024-06-26 12:07     ` Maximiliano Sandoval
2024-06-26 10:44 ` [pbs-devel] [PATCH proxmox 03/18] remove needless borrows Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 04/18] remove unnecesary pub(self) Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 05/18] time-api: remove redundant field names Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 06/18] acme: remove duplicated attribute Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 07/18] acl: remove null pointer cast Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 08/18] use const blocks in thread_local! calls Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 09/18] remove unneeded returns Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 10/18] shared-memory: remove unneeded generic parameter Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 11/18] network-api: remove useless uses of format! Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 12/18] http: remove redundant redefinition of binding Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 13/18] http: remove unnecessary cast Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 14/18] acme: elide explicit lifetimes Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 15/18] acme: derive Default for Status Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 16/18] acl: directly return struct rather than a binding Maximiliano Sandoval
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 17/18] acme-api: remove manual implementation of Option::map Maximiliano Sandoval
2024-06-26 11:36   ` Shannon Sterz
2024-06-26 10:45 ` [pbs-devel] [PATCH proxmox 18/18] auth-api: do not clone struct implementing Copy Maximiliano Sandoval

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=D29WMWWGKLD4.2RL0UQ9TSHNK7@proxmox.com \
    --to=s.sterz@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal