[PATCH installer v3 27/38] common: options: move regex construction out of loop

Christoph Heiss
2026-04-03T16:56:39Z

.. and make clippy happy.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v2 -> v3:
* new patch

proxmox-installer-common/src/options.rs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs
index fbc0207..dcf4fe7 100644
--- a/proxmox-installer-common/src/options.rs
+++ b/proxmox-installer-common/src/options.rs
@@ -502,6 +502,15 @@ impl NetworkInterfacePinningOptions {
/// - only contains ASCII alphanumeric characters and underscore, as
/// enforced by our `pve-iface` json schema.
pub fn verify(&self) -> Result<()> {
+ // Mimicking the `pve-iface` schema verification
+ static RE: OnceLock<Regex> = OnceLock::new();
+ let re = RE.get_or_init(|| {
+ RegexBuilder::new(r"^[a-z][a-z0-9_]{1,20}([:\.]\d+)?$")
+ .case_insensitive(true)
+ .build()
+ .unwrap()
+ });
+
let mut reverse_mapping = HashMap::<String, String>::new();
for (mac, name) in self.mapping.iter() {
if name.len() < MIN_IFNAME_LEN {
@@ -517,15 +526,6 @@ impl NetworkInterfacePinningOptions {
);
}

- // Mimicking the `pve-iface` schema verification
- static RE: OnceLock<Regex> = OnceLock::new();
- let re = RE.get_or_init(|| {
- RegexBuilder::new(r"^[a-z][a-z0-9_]{1,20}([:\.]\d+)?$")
- .case_insensitive(true)
- .build()
- .unwrap()
- });
-
if !re.is_match(name) {
bail!(
"interface name '{name}' for '{mac}' is invalid: name must start with a letter and contain only ascii characters, digits and underscores"
--
2.53.0