From b68c5973e3ea2fea1bec8f598989c4abec3b65ee Mon Sep 17 00:00:00 2001 From: Bryan Henry Date: Fri, 27 Aug 2021 12:18:58 -0700 Subject: [PATCH 1/3] Make ParseErrorKind public and available through ParseError::kind() ParseErrorKind has also been made #[non_exhaustive] to avoid committing to only the current set of error kinds, i.e. so that it can be expanded as needed without an SemVer-breaking change. --- src/format/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index 1cc5048c16..fdb119e608 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -338,9 +338,17 @@ macro_rules! internal_fix { #[derive(Debug, Clone, PartialEq, Eq, Copy)] pub struct ParseError(ParseErrorKind); +impl ParseError { + /// The category of parse error + pub fn kind(&self) -> ParseErrorKind { + self.0 + } +} + /// The category of parse error #[derive(Debug, Clone, PartialEq, Eq, Copy)] -enum ParseErrorKind { +#[non_exhaustive] +pub enum ParseErrorKind { /// Given field is out of permitted range. OutOfRange, From be9ed08d190df8a176eb6a29b46fbde31a3ace8d Mon Sep 17 00:00:00 2001 From: Bryan Henry Date: Fri, 27 Aug 2021 12:23:02 -0700 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16a9063b60..e59f56f803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Versions with only mechanical changes will be omitted from the following list. * Add support for microseconds timestamps serde serialization/deserialization (#304) * Fix `DurationRound` is not TZ aware (#495) * Implement `DurationRound` for `NaiveDateTime` +* Make `ParseErrorKind` public and available through `ParseError::kind()` ## 0.4.19 From 787965c910e7c78c0e6f4d14007bea6510825a4f Mon Sep 17 00:00:00 2001 From: Erlend Langseth <3rlendhl@gmail.com> Date: Fri, 13 May 2022 10:32:12 +0200 Subject: [PATCH 3/3] ParseErrorKind::__Nonexhaustive until MSRV is increased --- src/format/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index 4e5a46c11a..722adbb6ad 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -348,7 +348,6 @@ impl ParseError { /// The category of parse error #[derive(Debug, Clone, PartialEq, Eq, Copy)] -#[non_exhaustive] pub enum ParseErrorKind { /// Given field is out of permitted range. OutOfRange, @@ -377,6 +376,10 @@ pub enum ParseErrorKind { /// There was an error on the formatting string, or there were non-supported formating items. BadFormat, + + // TODO: Change this to `#[non_exhaustive]` (on the enum) when MSRV is increased + #[doc(hidden)] + __Nonexhaustive, } /// Same as `Result`. @@ -392,6 +395,7 @@ impl fmt::Display for ParseError { ParseErrorKind::TooShort => write!(f, "premature end of input"), ParseErrorKind::TooLong => write!(f, "trailing input"), ParseErrorKind::BadFormat => write!(f, "bad or unsupported format string"), + _ => unreachable!(), } } }