From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id BF60F1FF2D4 for ; Tue, 9 Jul 2024 08:18:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C2F751856E; Tue, 9 Jul 2024 08:19:05 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Tue, 9 Jul 2024 08:18:28 +0200 Message-Id: <20240709061832.52121-2-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240709061832.52121-1-w.bumiller@proxmox.com> References: <20240709061832.52121-1-w.bumiller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.087 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, lib.rs] Subject: [pbs-devel] [PATCH proxmox 2/6] apt-api-types: use serde-plain to display/parse enums X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" From: Dietmar Maurer Signed-off-by: Dietmar Maurer --- proxmox-apt-api-types/Cargo.toml | 2 +- proxmox-apt-api-types/debian/control | 8 ++--- proxmox-apt-api-types/src/lib.rs | 48 ++++------------------------ 3 files changed, 12 insertions(+), 46 deletions(-) diff --git a/proxmox-apt-api-types/Cargo.toml b/proxmox-apt-api-types/Cargo.toml index e2ab46ad..e6482146 100644 --- a/proxmox-apt-api-types/Cargo.toml +++ b/proxmox-apt-api-types/Cargo.toml @@ -9,7 +9,7 @@ exclude.workspace = true description = "APT API type definitions." [dependencies] -anyhow.workspace = true serde = { workspace = true, features = ["derive"] } +serde_plain.workspace = true proxmox-schema = { workspace = true, features = ["api-macro"] } proxmox-config-digest.workspace = true diff --git a/proxmox-apt-api-types/debian/control b/proxmox-apt-api-types/debian/control index 708e8c4b..5b50e114 100644 --- a/proxmox-apt-api-types/debian/control +++ b/proxmox-apt-api-types/debian/control @@ -6,12 +6,12 @@ Build-Depends: debhelper (>= 12), cargo:native , rustc:native , libstd-rust-dev , - librust-anyhow-1+default-dev , librust-proxmox-config-digest-0.1+default-dev , librust-proxmox-schema-3+api-macro-dev (>= 3.1.1-~~) , librust-proxmox-schema-3+default-dev (>= 3.1.1-~~) , librust-serde-1+default-dev , - librust-serde-1+derive-dev + librust-serde-1+derive-dev , + librust-serde-plain-1+default-dev Maintainer: Proxmox Support Team Standards-Version: 4.6.2 Vcs-Git: git://git.proxmox.com/git/proxmox-apt.git @@ -24,12 +24,12 @@ Architecture: any Multi-Arch: same Depends: ${misc:Depends}, - librust-anyhow-1+default-dev, librust-proxmox-config-digest-0.1+default-dev, librust-proxmox-schema-3+api-macro-dev (>= 3.1.1-~~), librust-proxmox-schema-3+default-dev (>= 3.1.1-~~), librust-serde-1+default-dev, - librust-serde-1+derive-dev + librust-serde-1+derive-dev, + librust-serde-plain-1+default-dev Provides: librust-proxmox-apt-api-types+default-dev (= ${binary:Version}), librust-proxmox-apt-api-types-1-dev (= ${binary:Version}), diff --git a/proxmox-apt-api-types/src/lib.rs b/proxmox-apt-api-types/src/lib.rs index 3b6ac9e4..80d5ec4b 100644 --- a/proxmox-apt-api-types/src/lib.rs +++ b/proxmox-apt-api-types/src/lib.rs @@ -1,6 +1,5 @@ use std::fmt::Display; -use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; use proxmox_config_digest::ConfigDigest; @@ -16,26 +15,8 @@ pub enum APTRepositoryFileType { Sources, } -impl TryFrom<&str> for APTRepositoryFileType { - type Error = Error; - - fn try_from(file_type: &str) -> Result { - match file_type { - "list" => Ok(APTRepositoryFileType::List), - "sources" => Ok(APTRepositoryFileType::Sources), - _ => bail!("invalid file type '{file_type}'"), - } - } -} - -impl Display for APTRepositoryFileType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - APTRepositoryFileType::List => write!(f, "list"), - APTRepositoryFileType::Sources => write!(f, "sources"), - } - } -} +serde_plain::derive_display_from_serialize!(APTRepositoryFileType); +serde_plain::derive_fromstr_from_deserialize!(APTRepositoryFileType); #[api] #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] @@ -47,26 +28,8 @@ pub enum APTRepositoryPackageType { DebSrc, } -impl TryFrom<&str> for APTRepositoryPackageType { - type Error = Error; - - fn try_from(package_type: &str) -> Result { - match package_type { - "deb" => Ok(APTRepositoryPackageType::Deb), - "deb-src" => Ok(APTRepositoryPackageType::DebSrc), - _ => bail!("invalid package type '{package_type}'"), - } - } -} - -impl Display for APTRepositoryPackageType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - APTRepositoryPackageType::Deb => write!(f, "deb"), - APTRepositoryPackageType::DebSrc => write!(f, "deb-src"), - } - } -} +serde_plain::derive_display_from_serialize!(APTRepositoryPackageType); +serde_plain::derive_fromstr_from_deserialize!(APTRepositoryPackageType); #[api( properties: { @@ -327,6 +290,9 @@ pub enum APTRepositoryHandle { CephReefTest, } +serde_plain::derive_display_from_serialize!(APTRepositoryHandle); +serde_plain::derive_fromstr_from_deserialize!(APTRepositoryHandle); + #[api()] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel