Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ParseErrorKind public and available through ParseError::kind() #588

Merged
merged 6 commits into from Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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