From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 09/14] post-hook: avoid redundant Option<bool> for (de-)serialization
Date: Tue, 14 Oct 2025 15:21:54 +0200 [thread overview]
Message-ID: <20251014132207.1171073-10-c.heiss@proxmox.com> (raw)
In-Reply-To: <20251014132207.1171073-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>
---
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
next prev parent reply other threads:[~2025-10-14 13:23 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 13:21 [pve-devel] [PATCH installer 00/14] support network interface name pinning Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 01/14] test: parse-kernel-cmdline: fix module import statement Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 02/14] install: add support for network interface name pinning Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 03/14] run env: network: add kernel driver name to network interface info Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 04/14] common: utils: fix clippy warnings Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 05/14] common: setup: simplify network address list serialization Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 06/14] common: implement support for `network_interface_pin_map` config Christoph Heiss
2025-10-21 14:05 ` Michael Köppl
2025-10-22 9:37 ` Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 07/14] auto: add support for pinning network interface names Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 08/14] assistant: verify network settings in `validate-answer` subcommand Christoph Heiss
2025-10-14 13:21 ` Christoph Heiss [this message]
2025-10-14 13:21 ` [pve-devel] [PATCH installer 10/14] post-hook: add network interface name and pinning status Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 11/14] tui: views: move network options view to own module Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 12/14] tui: views: form: allow attaching user-defined data to children Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 13/14] tui: add support for pinning network interface names Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 14/14] gui: " Christoph Heiss
2025-10-14 15:04 ` Maximiliano Sandoval
2025-10-16 12:01 ` Christoph Heiss
2025-10-21 14:05 ` Michael Köppl
2025-10-22 9:40 ` Christoph Heiss
2025-10-21 14:04 ` [pve-devel] [PATCH installer 00/14] support network interface name pinning Michael Köppl
2025-10-22 9:46 ` 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=20251014132207.1171073-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.