Option<Vec<..>> is redundant in combination with #[serde(default)], as the latter already defaults to an empty Vec<..> if the key does not exist.
No functional changes. Signed-off-by: Christoph Heiss <[email protected]> --- Changes v1 -> v2: * no changes proxmox-installer-common/src/options.rs | 26 ++++++++++--------------- proxmox-installer-common/src/setup.rs | 6 +++--- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 50fd74e..59e8560 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -518,24 +518,20 @@ impl NetworkOptions { if let Some(gw) = &routes.gateway4 { if let Some(iface) = network.interfaces.get(&gw.dev) { this.ifname.clone_from(&iface.name); - if let Some(addresses) = &iface.addresses { - if let Some(addr) = addresses.iter().find(|addr| addr.is_ipv4()) { - this.gateway = gw.gateway; - this.address = addr.clone(); - filled = true; - } + if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv4()) { + this.gateway = gw.gateway; + this.address = addr.clone(); + filled = true; } } } if !filled { if let Some(gw) = &routes.gateway6 { if let Some(iface) = network.interfaces.get(&gw.dev) { - if let Some(addresses) = &iface.addresses { - if let Some(addr) = addresses.iter().find(|addr| addr.is_ipv6()) { - this.ifname.clone_from(&iface.name); - this.gateway = gw.gateway; - this.address = addr.clone(); - } + if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv6()) { + this.ifname.clone_from(&iface.name); + this.gateway = gw.gateway; + this.address = addr.clone(); } } } @@ -679,9 +675,7 @@ mod tests { state: InterfaceState::Up, driver: "dummy".to_owned(), mac: "01:23:45:67:89:ab".to_owned(), - addresses: Some(vec![ - CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(), - ]), + addresses: vec![CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap()], }, ); @@ -807,7 +801,7 @@ mod tests { state: InterfaceState::Up, driver: "dummy".to_owned(), mac: "01:23:45:67:89:ab".to_owned(), - addresses: None, + addresses: vec![], }, ); diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 4fda39d..4873fff 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -321,7 +321,7 @@ where .collect()) } -fn deserialize_cidr_list<'de, D>(deserializer: D) -> Result<Option<Vec<CidrAddress>>, D::Error> +fn deserialize_cidr_list<'de, D>(deserializer: D) -> Result<Vec<CidrAddress>, D::Error> where D: Deserializer<'de>, { @@ -347,7 +347,7 @@ where ); } - Ok(Some(result)) + Ok(result) } fn serialize_as_display<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error> @@ -478,7 +478,7 @@ pub struct Interface { #[serde(default)] #[serde(deserialize_with = "deserialize_cidr_list")] - pub addresses: Option<Vec<CidrAddress>>, + pub addresses: Vec<CidrAddress>, } impl Interface { -- 2.51.0 _______________________________________________ pve-devel mailing list [email protected] https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
