From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 174121FF185 for ; Mon, 7 Jul 2025 12:08:35 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B596E1F317; Mon, 7 Jul 2025 12:09:10 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 7 Jul 2025 12:08:14 +0200 Message-ID: <20250707100830.550898-3-c.heiss@proxmox.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250707100830.550898-1-c.heiss@proxmox.com> References: <20250707100830.550898-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH installer v2 2/2] auto: answer: simplify `BTreeMap` handling in deserialization X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Instead of using an `Option>`, we can use a `BTreeMap` directly and let serde default to an empty map. No functional changes. Signed-off-by: Christoph Heiss --- Changes v1 -> v2: * rebased on latest master proxmox-auto-installer/src/answer.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs index c500933..b461976 100644 --- a/proxmox-auto-installer/src/answer.rs +++ b/proxmox-auto-installer/src/answer.rs @@ -185,7 +185,8 @@ struct NetworkInAnswer { pub cidr: Option, pub dns: Option, pub gateway: Option, - pub filter: Option>, + #[serde(default)] + pub filter: BTreeMap, } #[derive(Clone, Deserialize, Debug)] @@ -208,7 +209,7 @@ impl TryFrom 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."); } @@ -217,7 +218,7 @@ impl TryFrom for Network { cidr: network.cidr.unwrap(), dns: network.dns.unwrap(), gateway: network.gateway.unwrap(), - filter: network.filter.unwrap(), + filter: network.filter, }), }) } else { @@ -230,7 +231,7 @@ impl TryFrom 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."); } @@ -261,7 +262,8 @@ pub struct DiskSetup { pub filesystem: Filesystem, #[serde(alias = "disk_list", default)] pub disk_list: Vec, - pub filter: Option>, + #[serde(default)] + pub filter: BTreeMap, #[serde(alias = "filter_match")] pub filter_match: Option, pub zfs: Option, @@ -282,17 +284,17 @@ impl TryFrom for Disks { type Error = &'static str; fn try_from(source: DiskSetup) -> Result { - if source.disk_list.is_empty() && source.filter.is_none() { + 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() { + 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