Skip to content

Commit

Permalink
Make ParseErrorKind public and available through ParseError::kind() (#…
Browse files Browse the repository at this point in the history
…588)

Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
Co-authored-by: Erlend Langseth <3rlendhl@gmail.com>
  • Loading branch information
3 people committed Jun 9, 2022
1 parent 150f6d1 commit d7c743e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
14 changes: 13 additions & 1 deletion src/format/mod.rs
Expand Up @@ -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,

Expand Down Expand Up @@ -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<T, ParseError>`.
Expand All @@ -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!(),
}
}
}
Expand Down

0 comments on commit d7c743e

Please sign in to comment.