[pve-devel] [PATCH installer 09/14] post-hook: avoid redundant Option<bool> for (de-)serialization

Christoph Heiss c.heiss at proxmox.com
Tue Oct 14 15:21:54 CEST 2025


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 at proxmox.com>
---
 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





More information about the pve-devel mailing list