diff options
author | Ben Boeckel <mathstuf@gmail.com> | 2020-04-08 23:18:49 -0400 |
---|---|---|
committer | Ben Boeckel <mathstuf@gmail.com> | 2020-04-09 10:32:32 -0400 |
commit | f08ee3c272ddf01b1025abb0c8a81fdd15a6bf52 (patch) | |
tree | 59fce98d78cdfd87075a44805a7afbc8441a2836 | |
parent | 4daf9712dda43cd0176400a6fcc89d948e43244d (diff) |
error: mark chrono parsing errors as an error source
-rw-r--r-- | src/error.rs | 7 | ||||
-rw-r--r-- | src/icalendar.rs | 27 |
2 files changed, 17 insertions, 17 deletions
diff --git a/src/error.rs b/src/error.rs index 13c268d..4c48e50 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,8 +17,11 @@ pub enum VObjectErrorKind { NotAnICalendar(String), #[cfg(feature = "timeconversions")] - #[error("{}", _0)] - ChronoError(::chrono::format::ParseError), + #[error("failed to parse time")] + ChronoError { + #[from] + source: chrono::format::ParseError, + }, } pub(crate) type VObjectResult<T> = Result<T, VObjectErrorKind>; diff --git a/src/icalendar.rs b/src/icalendar.rs index 4863029..6a5fea2 100644 --- a/src/icalendar.rs +++ b/src/icalendar.rs @@ -166,12 +166,11 @@ pub trait AsDateTime { impl AsDateTime for Dtend { fn as_datetime(&self) -> VObjectResult<Time> { - match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { - Ok(dt) => Ok(Time::DateTime(dt)), + Ok(match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { + Ok(dt) => Time::DateTime(dt), Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT) - .map(Time::Date) - .map_err(VObjectErrorKind::ChronoError), - } + .map(Time::Date)?, + }) } } @@ -180,12 +179,11 @@ impl AsDateTime for Dtend { impl AsDateTime for Dtstart { fn as_datetime(&self) -> VObjectResult<Time> { - match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { - Ok(dt) => Ok(Time::DateTime(dt)), + Ok(match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { + Ok(dt) => Time::DateTime(dt), Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT) - .map(Time::Date) - .map_err(VObjectErrorKind::ChronoError), - } + .map(Time::Date)?, + }) } } @@ -194,12 +192,11 @@ impl AsDateTime for Dtstart { impl AsDateTime for Dtstamp { fn as_datetime(&self) -> VObjectResult<Time> { - match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { - Ok(dt) => Ok(Time::DateTime(dt)), + Ok(match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) { + Ok(dt) => Time::DateTime(dt), Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT) - .map(Time::Date) - .map_err(VObjectErrorKind::ChronoError), - } + .map(Time::Date)?, + }) } } |