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 v2 09/15] post-hook: avoid redundant Option<bool> for (de-)serialization
Date: Thu, 30 Oct 2025 12:06:11 +0100	[thread overview]
Message-ID: <20251030110627.812398-10-c.heiss@proxmox.com> (raw)
In-Reply-To: <20251030110627.812398-1-c.heiss@proxmox.com>

Instead, for the serialization case just skip it if the value is falsy,
for deserialization default-initialize it with `false`.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v1 -> v2:
  * no changes

 proxmox-installer-common/src/setup.rs | 12 ++----------
 proxmox-post-hook/src/main.rs         | 27 +++++++++++++++------------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index 3e99576..1a584ba 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -275,14 +275,6 @@ where
     Ok(val != 0)
 }
 
-fn deserialize_bool_from_int_maybe<'de, D>(deserializer: D) -> Result<Option<bool>, D::Error>
-where
-    D: Deserializer<'de>,
-{
-    let val: Option<u32> = Deserialize::deserialize(deserializer)?;
-    Ok(val.map(|v| v != 0))
-}
-
 fn deserialize_cczones_map<'de, D>(
     deserializer: D,
 ) -> Result<HashMap<String, Vec<String>>, D::Error>
@@ -389,8 +381,8 @@ pub struct RuntimeInfo {
     pub hvm_supported: bool,
 
     /// Whether the system was booted with SecureBoot enabled
-    #[serde(default, deserialize_with = "deserialize_bool_from_int_maybe")]
-    pub secure_boot: Option<bool>,
+    #[serde(default, deserialize_with = "deserialize_bool_from_int")]
+    pub secure_boot: bool,
 
     /// Default upper limit for the ZFS ARC size, in MiB.
     pub default_zfs_arc_max: usize,
diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs
index bd27121..0a9e661 100644
--- a/proxmox-post-hook/src/main.rs
+++ b/proxmox-post-hook/src/main.rs
@@ -44,8 +44,8 @@ struct BootInfo {
     /// Whether the system is booted using UEFI or legacy BIOS.
     mode: BootType,
     /// Whether SecureBoot is enabled for the installation.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    secureboot: Option<bool>,
+    #[serde(skip_serializing_if = "bool_is_false")]
+    secureboot: bool,
 }
 
 /// Holds all the public keys for the different algorithms available.
@@ -66,8 +66,8 @@ struct DiskInfo {
     /// Size in bytes
     size: usize,
     /// Set to true if the disk is used for booting.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    is_bootdisk: Option<bool>,
+    #[serde(skip_serializing_if = "bool_is_false")]
+    is_bootdisk: bool,
     /// Properties about the device as given by udev.
     udev_properties: UdevProperties,
 }
@@ -83,12 +83,16 @@ struct NetworkInterfaceInfo {
     address: Option<CidrAddress>,
     /// Set to true if the interface is the chosen management interface during
     /// installation.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    is_management: Option<bool>,
+    #[serde(skip_serializing_if = "bool_is_false")]
+    is_management: bool,
     /// Properties about the device as given by udev.
     udev_properties: UdevProperties,
 }
 
+fn bool_is_false(value: &bool) -> bool {
+    !value
+}
+
 /// Information about the installed product itself.
 #[derive(Serialize)]
 #[serde(rename_all = "kebab-case")]
@@ -323,7 +327,8 @@ impl PostHookInfo {
                     let is_bootdisk = config
                         .target_hd
                         .as_ref()
-                        .and_then(|hd| (*hd == disk.path).then_some(true));
+                        .map(|hd| *hd == disk.path)
+                        .unwrap_or_default();
 
                     anyhow::Ok(DiskInfo {
                         size: (config.hdsize * (SIZE_GIB as f64)) as usize,
@@ -341,9 +346,7 @@ impl PostHookInfo {
                 .disks
                 .iter()
                 .flat_map(|disk| {
-                    let is_bootdisk = selected_disks_indices
-                        .contains(&&disk.index)
-                        .then_some(true);
+                    let is_bootdisk = selected_disks_indices.contains(&&disk.index);
 
                     anyhow::Ok(DiskInfo {
                         size: (config.hdsize * (SIZE_GIB as f64)) as usize,
@@ -389,14 +392,14 @@ impl PostHookInfo {
                     anyhow::Ok(NetworkInterfaceInfo {
                         mac: nic.mac.clone(),
                         address: Some(config.cidr.clone()),
-                        is_management: Some(true),
+                        is_management: true,
                         udev_properties,
                     })
                 } else {
                     anyhow::Ok(NetworkInterfaceInfo {
                         mac: nic.mac.clone(),
                         address: None,
-                        is_management: None,
+                        is_management: false,
                         udev_properties,
                     })
                 }
-- 
2.51.0



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


  parent reply	other threads:[~2025-10-30 11:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-30 11:06 [pve-devel] [PATCH installer v2 00/15] support network interface name pinning Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 01/15] test: parse-kernel-cmdline: fix module import statement Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 02/15] install: add support for network interface name pinning Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 03/15] run env: network: add kernel driver name to network interface info Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 04/15] common: utils: fix clippy warnings Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 05/15] common: setup: simplify network address list serialization Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 06/15] common: implement support for `network_interface_pin_map` config Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 07/15] auto: add support for pinning network interface names Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 08/15] assistant: verify network settings in `validate-answer` subcommand Christoph Heiss
2025-10-30 11:06 ` Christoph Heiss [this message]
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 10/15] post-hook: add network interface name and pinning status Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 11/15] tui: views: move network options view to own module Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 12/15] tui: views: form: allow attaching user-defined data to children Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 13/15] tui: add support for pinning network interface names Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 14/15] ui: gtk3: allow passing of dialog parent window Christoph Heiss
2025-10-30 11:06 ` [pve-devel] [PATCH installer v2 15/15] gui: add support for pinning network interface names Christoph Heiss

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=20251030110627.812398-10-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