[pve-devel] [PATCH proxmox-ve-rs 09/21] sdn: add name types
Gabriel Goller
g.goller at proxmox.com
Thu Jun 27 12:56:24 CEST 2024
On 26.06.2024 14:15, Stefan Hanreich wrote:
>diff --git a/proxmox-ve-config/src/sdn/mod.rs b/proxmox-ve-config/src/sdn/mod.rs
>new file mode 100644
>index 0000000..4e7c525
>--- /dev/null
>+++ b/proxmox-ve-config/src/sdn/mod.rs
>@@ -0,0 +1,240 @@
>+use std::{error::Error, fmt::Display, str::FromStr};
>+
>+use serde_with::DeserializeFromStr;
>+
>+use crate::firewall::types::Cidr;
>+
>+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
>+pub enum SdnNameError {
>+ Empty,
>+ TooLong,
>+ InvalidSymbols,
>+ InvalidSubnetCidr,
>+ InvalidSubnetFormat,
>+}
>+
>+impl Error for SdnNameError {}
>+
>+impl Display for SdnNameError {
>+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
>+ f.write_str(match self {
>+ SdnNameError::TooLong => "name too long",
>+ SdnNameError::InvalidSymbols => "invalid symbols in name",
>+ SdnNameError::InvalidSubnetCidr => "invalid cidr in name",
>+ SdnNameError::InvalidSubnetFormat => "invalid format for subnet name",
>+ SdnNameError::Empty => "name is empty",
>+ })
>+ }
>+}
>+
Hmm, maybe we should pull in the `thiserror` crate here...
There are a few error-enums that could benefit from it:
SdnNameError, IpamError, SdnConfigError, IpRangeError.
More information about the pve-devel
mailing list