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 8965F61D1E for ; Fri, 18 Dec 2020 12:37:35 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7E8842F848 for ; Fri, 18 Dec 2020 12:37:35 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 D953B2F81A for ; Fri, 18 Dec 2020 12:37:32 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A528945354 for ; Fri, 18 Dec 2020 12:26:24 +0100 (CET) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Fri, 18 Dec 2020 12:25:56 +0100 Message-Id: <20201218112608.6845-9-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201218112608.6845-1-w.bumiller@proxmox.com> References: <20201218112608.6845-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.018 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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. [util.rs] Subject: [pbs-devel] [PATCH proxmox 08/18] api-macro: add more standard Maybe methods 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: Fri, 18 Dec 2020 11:37:35 -0000 Note that any methods added there should be oriented around `Option`. Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/util.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/proxmox-api-macro/src/util.rs b/proxmox-api-macro/src/util.rs index e74e04b..87e6414 100644 --- a/proxmox-api-macro/src/util.rs +++ b/proxmox-api-macro/src/util.rs @@ -584,6 +584,12 @@ pub enum Maybe { None, } +impl Default for Maybe { + fn default() -> Self { + Maybe::None + } +} + impl Maybe { pub fn as_ref(&self) -> Maybe<&T> { match self { @@ -600,6 +606,13 @@ impl Maybe { } } + pub fn ok(self) -> Option { + match self { + Maybe::Explicit(v) | Maybe::Derived(v) => Some(v), + Maybe::None => None, + } + } + pub fn ok_or_else(self, other: F) -> Result where F: FnOnce() -> E, @@ -613,6 +626,14 @@ impl Maybe { pub fn is_none(&self) -> bool { matches!(self, Maybe::None) } + + pub fn is_explicit(&self) -> bool { + matches!(self, Maybe::Explicit(_)) + } + + pub fn take(&mut self) -> Self { + std::mem::take(self) + } } impl Into> for Maybe { -- 2.20.1