diff --git a/proxmox-time/src/calendar_event.rs b/proxmox-time/src/calendar_event.rs index a839f9d8..d1d74a28 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 8c5e1cf1..0476cc1c 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), };