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 526EB828DD for ; Tue, 30 Nov 2021 13:12:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 87CA626A3F for ; Tue, 30 Nov 2021 13:12:17 +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 E9EB126911 for ; Tue, 30 Nov 2021 13:12:11 +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 BE14E45438 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:07 +0100 Message-Id: <20211130121209.216846-14-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 13/14] proxmox-time: calendar_events: 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:43 -0000 and deprecate 'parse_calendar_event' Signed-off-by: Dominik Csapak --- proxmox-time/src/calendar_event.rs | 13 +++++++++++-- proxmox-time/src/test.rs | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/proxmox-time/src/calendar_event.rs b/proxmox-time/src/calendar_event.rs index a839f9d..d1d74a2 100644 --- a/proxmox-time/src/calendar_event.rs +++ b/proxmox-time/src/calendar_event.rs @@ -163,9 +163,17 @@ impl CalendarEvent { } } +impl std::str::FromStr for CalendarEvent { + type Err = Error; + + fn from_str(i: &str) -> Result { + parse_complete_line("calendar event", i, parse_calendar_event_incomplete) + } +} + /// Verify the format of the [CalendarEvent] pub fn verify_calendar_event(i: &str) -> Result<(), Error> { - parse_calendar_event(i)?; + let _: CalendarEvent = i.parse()?; Ok(()) } @@ -180,8 +188,9 @@ pub fn compute_next_event( } /// Parse a [CalendarEvent] +#[deprecated="use std::str::FromStr trait instead"] pub fn parse_calendar_event(i: &str) -> Result { - parse_complete_line("calendar event", i, parse_calendar_event_incomplete) + i.parse() } fn parse_calendar_event_incomplete(mut i: &str) -> IResult<&str, CalendarEvent> { diff --git a/proxmox-time/src/test.rs b/proxmox-time/src/test.rs index 8c5e1cf..0476cc1 100644 --- a/proxmox-time/src/test.rs +++ b/proxmox-time/src/test.rs @@ -3,7 +3,7 @@ use anyhow::bail; use super::*; fn test_event(v: &'static str) -> Result<(), Error> { - match parse_calendar_event(v) { + match v.parse::() { Ok(event) => println!("CalendarEvent '{}' => {:?}", v, event), Err(err) => bail!("parsing '{}' failed - {}", v, err), } @@ -18,7 +18,7 @@ const fn make_test_time(mday: i32, hour: i32, min: i32) -> i64 { #[test] fn test_compute_next_event() -> Result<(), Error> { let test_value = |v: &'static str, last: i64, expect: i64| -> Result { - let event = match parse_calendar_event(v) { + let event: CalendarEvent = match v.parse() { Ok(event) => event, Err(err) => bail!("parsing '{}' failed - {}", v, err), }; @@ -44,7 +44,7 @@ fn test_compute_next_event() -> Result<(), Error> { }; let test_never = |v: &'static str, last: i64| -> Result<(), Error> { - let event = match parse_calendar_event(v) { + let event: CalendarEvent = match v.parse() { Ok(event) => event, Err(err) => bail!("parsing '{}' failed - {}", v, err), }; -- 2.30.2