From: Christoph Heiss <c.heiss@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 4/5] ui: auto-installer: use .to_string() instead of manual serde variant
Date: Mon, 2 Nov 2026 13:49:36 +0100 [thread overview]
Message-ID: <20261102124939.1023342-5-c.heiss@proxmox.com> (raw)
In-Reply-To: <20261102124939.1023342-1-c.heiss@proxmox.com>
No functional changes.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
lib/pdm-api-types/src/auto_installer.rs | 1 +
ui/Cargo.toml | 2 +-
.../auto_installer/prepared_answer_form.rs | 41 +++++++------------
3 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/lib/pdm-api-types/src/auto_installer.rs b/lib/pdm-api-types/src/auto_installer.rs
index 4a2dce13..858bd0c2 100644
--- a/lib/pdm-api-types/src/auto_installer.rs
+++ b/lib/pdm-api-types/src/auto_installer.rs
@@ -87,6 +87,7 @@ pub enum DiskSelectionMode {
}
serde_plain::derive_fromstr_from_deserialize!(DiskSelectionMode);
+serde_plain::derive_display_from_serialize!(DiskSelectionMode);
const_regex! {
/// Regex for matching the key of udev filters.
diff --git a/ui/Cargo.toml b/ui/Cargo.toml
index 99ff5619..d3053802 100644
--- a/ui/Cargo.toml
+++ b/ui/Cargo.toml
@@ -38,7 +38,7 @@ proxmox-acme-api = "1"
proxmox-deb-version = "0.1"
proxmox-client = "1"
proxmox-human-byte = "1"
-proxmox-installer-types = "0.2"
+proxmox-installer-types = "0.3"
proxmox-login = "1"
proxmox-network-types = "1.1"
proxmox-schema = "5"
diff --git a/ui/src/remotes/auto_installer/prepared_answer_form.rs b/ui/src/remotes/auto_installer/prepared_answer_form.rs
index 960decae..0b01baf1 100644
--- a/ui/src/remotes/auto_installer/prepared_answer_form.rs
+++ b/ui/src/remotes/auto_installer/prepared_answer_form.rs
@@ -2,7 +2,7 @@
//! edit window, as well as some utility to collect and prepare the form data for submission.
use anyhow::{Result, anyhow, bail};
-use serde::{Deserialize, Serialize};
+use serde::Deserialize;
use serde_json::{Value, json};
use std::{collections::BTreeMap, ops::Deref, rc::Rc, sync::LazyLock};
@@ -248,7 +248,7 @@ pub fn render_global_options_form(
.items(Rc::new(
KEYBOARD_LAYOUTS
.iter()
- .map(|l| serde_variant_name(l).expect("valid variant").into())
+ .map(|l| l.to_string().into())
.collect(),
))
.render_value(|v: &AttrValue| {
@@ -257,7 +257,7 @@ pub fn render_global_options_form(
.unwrap_or_default()
.into()
})
- .value(serde_variant_name(config.keyboard))
+ .value(config.keyboard.to_string())
.filter(|item: &AttrValue, query: &str| {
let query = query.to_string().to_lowercase();
let item = item.to_string();
@@ -317,7 +317,7 @@ pub fn render_global_options_form(
.items(Rc::new(
[RebootMode::Reboot, RebootMode::PowerOff]
.iter()
- .map(|opt| serde_variant_name(opt).expect("valid variant").into())
+ .map(|m| m.to_string().into())
.collect(),
))
.render_value(|v: &AttrValue| match v.parse::<RebootMode>() {
@@ -325,7 +325,7 @@ pub fn render_global_options_form(
Ok(RebootMode::PowerOff) => tr!("Power off").into(),
_ => v.into(),
})
- .value(serde_variant_name(config.reboot_mode))
+ .value(config.reboot_mode.to_string())
.required(true),
)
.with_field(
@@ -482,7 +482,7 @@ pub fn render_disk_setup_form(
.items(Rc::new(
FILESYSTEM_TYPE_OPTIONS
.iter()
- .map(|opt| serde_variant_name(opt).expect("valid variant").into())
+ .map(|opt| opt.to_string().into())
.collect(),
))
.render_value(|v: &AttrValue| {
@@ -491,7 +491,7 @@ pub fn render_disk_setup_form(
.unwrap_or_default()
.into()
})
- .value(serde_variant_name(config.filesystem.to_type()))
+ .value(config.filesystem.to_type().to_string())
.required(true)
.show_filter(false),
)
@@ -508,7 +508,7 @@ pub fn render_disk_setup_form(
_ => v.into(),
})
.required(true)
- .value(serde_variant_name(config.disk_mode)),
+ .value(config.disk_mode.to_string()),
)
.with_field(
tr!("Disk Names"),
@@ -528,7 +528,7 @@ pub fn render_disk_setup_form(
.items(Rc::new(
[FilterMatch::Any, FilterMatch::All]
.iter()
- .map(|opt| serde_variant_name(opt).expect("valid variant").into())
+ .map(|opt| opt.to_string().into())
.collect(),
))
.render_value(|v: &AttrValue| match v.parse::<FilterMatch>() {
@@ -536,8 +536,8 @@ pub fn render_disk_setup_form(
Ok(FilterMatch::All) => tr!("Match All Filters").into(),
_ => v.into(),
})
- .default(serde_variant_name(FilterMatch::default()))
- .value(config.disk_filter_match.and_then(serde_variant_name))
+ .default(FilterMatch::default().to_string())
+ .value(config.disk_filter_match.map(|v| v.to_string()))
.disabled(disk_mode != DiskSelectionMode::Filter),
)
.with_large_field(
@@ -729,7 +729,7 @@ fn add_zfs_advanced_form_fields(panel: &mut InputPanel, fs_opts: &ZfsOptions) {
.items(Rc::new(
ZFS_CHECKSUM_OPTIONS
.iter()
- .map(|opt| serde_variant_name(opt).expect("valid variant").into())
+ .map(|opt| opt.to_string().into())
.collect(),
))
.render_value(|v: &AttrValue| {
@@ -751,7 +751,7 @@ fn add_zfs_advanced_form_fields(panel: &mut InputPanel, fs_opts: &ZfsOptions) {
.items(Rc::new(
ZFS_COMPRESS_OPTIONS
.iter()
- .map(|opt| serde_variant_name(opt).expect("valid variant").into())
+ .map(|opt| opt.to_string().into())
.collect(),
))
.render_value(|v: &AttrValue| {
@@ -789,7 +789,7 @@ fn add_btrfs_advanced_form_fields(panel: &mut InputPanel, fs_opts: &BtrfsOptions
.items(Rc::new(
BTRFS_COMPRESS_OPTIONS
.iter()
- .map(|opt| serde_variant_name(opt).expect("valid variant").into())
+ .map(|opt| opt.to_string().into())
.collect(),
))
.render_value(|v: &AttrValue| {
@@ -1223,19 +1223,6 @@ fn kv_list_to_template_counter_map_validate(v: &Vec<(String, Value)>) -> Result<
Ok(serde_json::to_value(map)?)
}
-fn serde_variant_name<T: Serialize>(ty: T) -> Option<String> {
- match serde_json::to_value(ty) {
- Ok(Value::String(s)) => Some(s),
- other => {
- log::warn!(
- "expected string of type {}, got {other:?}",
- std::any::type_name::<T>()
- );
- None
- }
- }
-}
-
const KEYBOARD_LAYOUTS: &[KeyboardLayout] = {
use KeyboardLayout::*;
&[
--
2.55.0
next prev parent reply other threads:[~2026-11-02 12:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 12:49 [PATCH datacenter-manager 0/5] auto-install: add support for VLAN and bond configurations Christoph Heiss
2026-11-02 12:49 ` [PATCH datacenter-manager 1/5] config: auto-install: add new options for configuring vlan and bond Christoph Heiss
2026-11-02 12:49 ` [PATCH datacenter-manager 2/5] api-types: auto-installer: " Christoph Heiss
2026-11-02 12:49 ` [PATCH datacenter-manager 3/5] api: auto-installer: wire up new vlan and bond network options Christoph Heiss
2026-11-02 12:49 ` Christoph Heiss [this message]
2026-11-02 12:49 ` [PATCH datacenter-manager 5/5] ui: auto-installer: add vlan and bond config as advanced options 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=20261102124939.1023342-5-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pdm-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox