all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 2/2] auto: answer: simplify `BTreeMap` handling in deserialization
Date: Tue, 29 Apr 2025 15:20:24 +0200	[thread overview]
Message-ID: <20250429132025.1543199-2-c.heiss@proxmox.com> (raw)
In-Reply-To: <20250429132025.1543199-1-c.heiss@proxmox.com>

Instead of using an `Option<BTreeMap<..>>`, we can use a `BTreeMap`
directly and let serde default to an empty map.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-auto-installer/src/answer.rs | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs
index cbf268d..f785d89 100644
--- a/proxmox-auto-installer/src/answer.rs
+++ b/proxmox-auto-installer/src/answer.rs
@@ -186,7 +186,8 @@ struct NetworkInAnswer {
     pub cidr: Option<CidrAddress>,
     pub dns: Option<IpAddr>,
     pub gateway: Option<IpAddr>,
-    pub filter: Option<BTreeMap<String, String>>,
+    #[serde(default)]
+    pub filter: BTreeMap<String, String>,
 }
 
 #[derive(Clone, Deserialize, Debug)]
@@ -209,7 +210,7 @@ impl TryFrom<NetworkInAnswer> for Network {
             if network.gateway.is_none() {
                 return Err("Field 'gateway' must be set.");
             }
-            if network.filter.is_none() {
+            if network.filter.is_empty() {
                 return Err("Field 'filter' must be set.");
             }
 
@@ -218,7 +219,7 @@ impl TryFrom<NetworkInAnswer> for Network {
                     cidr: network.cidr.unwrap(),
                     dns: network.dns.unwrap(),
                     gateway: network.gateway.unwrap(),
-                    filter: network.filter.unwrap(),
+                    filter: network.filter,
                 }),
             })
         } else {
@@ -231,7 +232,7 @@ impl TryFrom<NetworkInAnswer> for Network {
             if network.gateway.is_some() {
                 return Err("Field 'gateway' not supported for 'from-dhcp' config.");
             }
-            if network.filter.is_some() {
+            if !network.filter.is_empty() {
                 return Err("Field 'filter' not supported for 'from-dhcp' config.");
             }
 
@@ -262,7 +263,8 @@ pub struct DiskSetup {
     pub filesystem: Filesystem,
     #[serde(alias = "disk_list", default)]
     pub disk_list: Vec<String>,
-    pub filter: Option<BTreeMap<String, String>>,
+    #[serde(default)]
+    pub filter: BTreeMap<String, String>,
     #[serde(alias = "filter_match")]
     pub filter_match: Option<FilterMatch>,
     pub zfs: Option<ZfsOptions>,
@@ -283,17 +285,17 @@ impl TryFrom<DiskSetup> for Disks {
     type Error = &'static str;
 
     fn try_from(source: DiskSetup) -> Result<Self, Self::Error> {
-        if source.disk_list.is_empty() && source.filter.is_none() {
-            return Err("Need either 'disk_list' or 'filter' set");
+        if source.disk_list.is_empty() && source.filter.is_empty() {
+            return Err("Need either 'disk-list' or 'filter' set");
         }
-        if !source.disk_list.is_empty() && source.filter.is_some() {
-            return Err("Cannot use both, 'disk_list' and 'filter'");
+        if !source.disk_list.is_empty() && !source.filter.is_empty() {
+            return Err("Cannot use both, 'disk-list' and 'filter'");
         }
 
         let disk_selection = if !source.disk_list.is_empty() {
             DiskSelection::Selection(source.disk_list.clone())
         } else {
-            DiskSelection::Filter(source.filter.clone().unwrap())
+            DiskSelection::Filter(source.filter.clone())
         };
 
         let lvm_checks = |source: &DiskSetup| -> Result<(), Self::Error> {
-- 
2.49.0



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


      reply	other threads:[~2025-04-29 13:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-29 13:20 [pve-devel] [PATCH installer 1/2] auto: answer: drop unneeded #[serde(default)] attributes Christoph Heiss
2025-04-29 13:20 ` Christoph Heiss [this message]

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=20250429132025.1543199-2-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-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