diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a26d3f836..7562212808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Versions with only mechanical changes will be omitted from the following list. * Add support for microseconds timestamps serde serialization for `NaiveDateTime`. * Add support for optional timestamps serde serialization for `NaiveDateTime`. * Fix build for wasm32-unknown-emscripten (@yu-re-ka #593) +* Make `ParseErrorKind` public and available through `ParseError::kind()` (#588) * Implement `DoubleEndedIterator` for `NaiveDateDaysIterator` and `NaiveDateWeeksIterator` * Fix panicking when parsing a `DateTime` (@botahamec) diff --git a/src/format/mod.rs b/src/format/mod.rs index 893496a035..2089c4c06a 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -336,9 +336,16 @@ 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 { +pub enum ParseErrorKind { /// Given field is out of permitted range. OutOfRange, @@ -366,6 +373,10 @@ 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`. @@ -381,6 +392,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!(), } } }