From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 126A279508 for ; Tue, 4 May 2021 12:20:02 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 07CE327857 for ; Tue, 4 May 2021 12:19:32 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 4F27327845 for ; Tue, 4 May 2021 12:19:31 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 223DE42A44 for ; Tue, 4 May 2021 12:19:31 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Tue, 4 May 2021 12:19:30 +0200 Message-Id: <20210504101930.3590-2-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210504101930.3590-1-w.bumiller@proxmox.com> References: <20210504101930.3590-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.020 Adjusted score from AWL reputation of From: address 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. [acme.rs] Subject: [pbs-devel] [RFC backup 2/2] use api_string_type macro 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: , X-List-Received-Date: Tue, 04 May 2021 10:20:02 -0000 Signed-off-by: Wolfgang Bumiller --- src/api2/types/acme.rs | 68 ++++-------------------------------------- 1 file changed, 6 insertions(+), 62 deletions(-) diff --git a/src/api2/types/acme.rs b/src/api2/types/acme.rs index cc5df322..f66a0801 100644 --- a/src/api2/types/acme.rs +++ b/src/api2/types/acme.rs @@ -1,6 +1,3 @@ -use std::fmt; - -use anyhow::Error; use serde::{Deserialize, Serialize}; use proxmox::api::{api, schema::{Schema, StringSchema, ApiStringFormat}}; @@ -64,63 +61,10 @@ pub struct KnownAcmeDirectory { pub url: &'static str, } -#[api(format: &PROXMOX_SAFE_ID_FORMAT)] -/// ACME account name. -#[derive(Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] -#[serde(transparent)] -pub struct AcmeAccountName(String); - -impl AcmeAccountName { - pub fn into_string(self) -> String { - self.0 - } - - pub fn from_string(name: String) -> Result { - match &Self::API_SCHEMA { - Schema::String(s) => s.check_constraints(&name)?, - _ => unreachable!(), - } - Ok(Self(name)) - } - - pub unsafe fn from_string_unchecked(name: String) -> Self { - Self(name) - } -} - -impl std::ops::Deref for AcmeAccountName { - type Target = str; - - #[inline] - fn deref(&self) -> &str { - &self.0 - } -} - -impl std::ops::DerefMut for AcmeAccountName { - #[inline] - fn deref_mut(&mut self) -> &mut str { - &mut self.0 - } -} - -impl AsRef for AcmeAccountName { - #[inline] - fn as_ref(&self) -> &str { - self.0.as_ref() - } -} - -impl fmt::Debug for AcmeAccountName { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self.0, f) - } -} - -impl fmt::Display for AcmeAccountName { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(&self.0, f) - } +api_string_type! { + #[api(format: &PROXMOX_SAFE_ID_FORMAT)] + /// ACME account name. + #[derive(Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] + #[serde(transparent)] + pub struct AcmeAccountName(String); } -- 2.20.1