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 ParseIntError and IntErrorKind fully public #55705

Merged
merged 12 commits into from
Nov 26, 2018
20 changes: 18 additions & 2 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4768,14 +4768,30 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
#[derive(Debug, Clone, PartialEq, Eq)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct ParseIntError {
kind: IntErrorKind,
/// Stores the cause of parsing an integer failing
pub kind: IntErrorKind,
}

/// Enum to store the various types of errors that can cause parsing an integer to fail.
#[unstable(feature = "int_error_matching",
reason = "it can be useful to match errors when making error messages \
for integer parsing",
issue = "22639")]
#[derive(Debug, Clone, PartialEq, Eq)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tangential, but this could also derive Copy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As always, this is a trade-off between being slightly more convenient to users today v.s. being more flexible to library maintainers in the future (in the kind of variants we can add to this non-exhaustive enum).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I missed the non_exhaustive attribute, nevermind then!

enum IntErrorKind {
#[non_exhaustive]
pub enum IntErrorKind {
eopb marked this conversation as resolved.
Show resolved Hide resolved
/// Value being parsed is empty.
///
/// Among other causes, this variant will be constructed when parsing an empty string.
Empty,
/// Contains an invalid digit.
///
/// Among other causes, this variant will be constructed when parsing a string that
/// contains a letter.
InvalidDigit,
/// Integer is too small to store in target integer type.
Overflow,
/// Integer is too large to store in target integer type.
Underflow,
}

Expand Down