Skip to content

Commit 423291f

Browse files
committed
Auto merge of #55705 - ethanboxx:master, r=SimonSapin
Make `ParseIntError` and `IntErrorKind` fully public Why would you write nice error types if I can't read them? # Why It can be useful to use `match` with errors produced when parsing strings to int. This would be useful for the `.err_match()` function in my [new crate](https://crates.io/crates/read_input). --- I could also do this for `ParseFloatError` if people think it is a good idea. I am new around hear so please tell me if I am getting anything wrong.
2 parents c14ab13 + 121e5e8 commit 423291f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/libcore/num/mod.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -4759,15 +4759,38 @@ pub struct ParseIntError {
47594759
kind: IntErrorKind,
47604760
}
47614761

4762+
/// Enum to store the various types of errors that can cause parsing an integer to fail.
4763+
#[unstable(feature = "int_error_matching",
4764+
reason = "it can be useful to match errors when making error messages \
4765+
for integer parsing",
4766+
issue = "22639")]
47624767
#[derive(Debug, Clone, PartialEq, Eq)]
4763-
enum IntErrorKind {
4768+
#[non_exhaustive]
4769+
pub enum IntErrorKind {
4770+
/// Value being parsed is empty.
4771+
///
4772+
/// Among other causes, this variant will be constructed when parsing an empty string.
47644773
Empty,
4774+
/// Contains an invalid digit.
4775+
///
4776+
/// Among other causes, this variant will be constructed when parsing a string that
4777+
/// contains a letter.
47654778
InvalidDigit,
4779+
/// Integer is too large to store in target integer type.
47664780
Overflow,
4781+
/// Integer is too small to store in target integer type.
47674782
Underflow,
47684783
}
47694784

47704785
impl ParseIntError {
4786+
/// Outputs the detailed cause of parsing an integer failing.
4787+
#[unstable(feature = "int_error_matching",
4788+
reason = "it can be useful to match errors when making error messages \
4789+
for integer parsing",
4790+
issue = "22639")]
4791+
pub fn kind(&self) -> &IntErrorKind {
4792+
&self.kind
4793+
}
47714794
#[unstable(feature = "int_error_internals",
47724795
reason = "available through Error trait and this method should \
47734796
not be exposed publicly",

0 commit comments

Comments
 (0)