From cb0440387b5ef3ef3c2c65e72e60c425bab667ac Mon Sep 17 00:00:00 2001 From: Nora Date: Wed, 27 Mar 2019 15:15:34 +0100 Subject: icalvevent: make get_duration_internal a little more elegant --- src/icalwrap/icalvevent.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/icalwrap/icalvevent.rs b/src/icalwrap/icalvevent.rs index 12b1ab9..2b48835 100644 --- a/src/icalwrap/icalvevent.rs +++ b/src/icalwrap/icalvevent.rs @@ -64,16 +64,13 @@ impl IcalVEvent { } pub fn get_duration(&self) -> Option { - match self.get_duration_internal() { - Some(duration) => Some(duration), - None => { - if self.get_dtstart()?.is_date() { - Some(IcalDuration::from_seconds(24 * 60 * 60)) - } else { - Some(IcalDuration::from_seconds(0)) - } + self.get_duration_internal().or_else(|| { + if self.get_dtstart()?.is_date() { + Some(IcalDuration::from_seconds(24 * 60 * 60)) + } else { + Some(IcalDuration::from_seconds(0)) } - } + }) } pub fn get_dtstart(&self) -> Option { @@ -317,10 +314,7 @@ mod tests { let cal = IcalVCalendar::from_str(testdata::TEST_DTSTART_ONLY_DATETIME, None).unwrap(); let event = cal.get_principal_event(); - assert_eq!( - Some(IcalDuration::from_seconds(0)), - event.get_duration() - ); + assert_eq!(Some(IcalDuration::from_seconds(0)), event.get_duration()); } #[test] -- cgit v1.2.3