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 5E3988286D for ; Tue, 30 Nov 2021 13:12:48 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E890926A3B for ; Tue, 30 Nov 2021 13:12:16 +0100 (CET) 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 17FE526913 for ; Tue, 30 Nov 2021 13:12:12 +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 E777944CE9 for ; Tue, 30 Nov 2021 13:12:11 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 30 Nov 2021 13:12:08 +0100 Message-Id: <20211130121209.216846-15-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211130121209.216846-1-d.csapak@proxmox.com> References: <20211130121209.216846-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.184 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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. [test.rs] Subject: [pbs-devel] [PATCH proxmox 14/14] proxmox-time: time-span: implement FromStr 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, 30 Nov 2021 12:12:48 -0000 and deprecate 'parse_time_span' Signed-off-by: Dominik Csapak --- proxmox-time/src/test.rs | 2 +- proxmox-time/src/time_span.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/proxmox-time/src/test.rs b/proxmox-time/src/test.rs index 0476cc1..ec63a37 100644 --- a/proxmox-time/src/test.rs +++ b/proxmox-time/src/test.rs @@ -225,7 +225,7 @@ fn test_calendar_event_weekday() -> Result<(), Error> { #[test] fn test_time_span_parser() -> Result<(), Error> { let test_value = |ts_str: &str, expect: f64| -> Result<(), Error> { - let ts = parse_time_span(ts_str)?; + let ts: TimeSpan = ts_str.parse()?; assert_eq!(f64::from(ts), expect, "{}", ts_str); Ok(()) }; diff --git a/proxmox-time/src/time_span.rs b/proxmox-time/src/time_span.rs index 2f8cf59..0a6c9ca 100644 --- a/proxmox-time/src/time_span.rs +++ b/proxmox-time/src/time_span.rs @@ -198,9 +198,18 @@ fn parse_time_unit(i: &str) -> IResult<&str, &str> { } } +impl std::str::FromStr for TimeSpan { + type Err = Error; + + fn from_str(i: &str) -> Result { + parse_complete_line("calendar event", i, parse_time_span_incomplete) + } +} + /// Parse a [TimeSpan] +#[deprecated="Use std::str::FromStr trait instead."] pub fn parse_time_span(i: &str) -> Result { - parse_complete_line("time span", i, parse_time_span_incomplete) + i.parse() } fn parse_time_span_incomplete(mut i: &str) -> IResult<&str, TimeSpan> { @@ -259,7 +268,7 @@ fn parse_time_span_incomplete(mut i: &str) -> IResult<&str, TimeSpan> { /// Verify the format of the [TimeSpan] pub fn verify_time_span(i: &str) -> Result<(), Error> { - parse_time_span(i)?; + let _: TimeSpan = i.parse()?; Ok(()) } -- 2.30.2