Signed-off-by: Michael Köppl <m.koe...@proxmox.com> --- proxmox-installer-common/src/utils.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/proxmox-installer-common/src/utils.rs b/proxmox-installer-common/src/utils.rs index 8adcec0..1fe6a74 100644 --- a/proxmox-installer-common/src/utils.rs +++ b/proxmox-installer-common/src/utils.rs @@ -18,6 +18,20 @@ pub enum CidrAddressParseError { InvalidMask(Option<ParseIntError>), } +impl fmt::Display for CidrAddressParseError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let msg = match &self { + CidrAddressParseError::NoDelimiter => { + String::from("No delimiter for separating address and mask was found") + } + CidrAddressParseError::InvalidAddr(addr_parse_error) => format!("{addr_parse_error}"), + CidrAddressParseError::InvalidMask(parse_int_error) => format!("{:?}", parse_int_error), + }; + + write!(f, "Invalid CIDR: {msg}") + } +} + /// An IP address (IPv4 or IPv6), including network mask. /// /// See the [`IpAddr`] type for more information how IP addresses are handled. @@ -109,8 +123,7 @@ impl<'de> Deserialize<'de> for CidrAddress { D: serde::Deserializer<'de>, { let s: String = Deserialize::deserialize(deserializer)?; - s.parse() - .map_err(|_| serde::de::Error::custom("invalid CIDR")) + s.parse().map_err(serde::de::Error::custom) } } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel