diff options
| author | bors <bors@rust-lang.org> | 2018-11-26 01:46:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-11-26 01:46:18 +0000 |
| commit | 423291f14bbb820265b2bbf33d6fffb044035b86 (patch) | |
| tree | d5a500b213463efcafdb9d4bfd747e53f64f7ed5 /src | |
| parent | c14ab13e618958bcb353b4e3c2eb2228475aa1ab (diff) | |
| parent | 121e5e806e41c4825fc4a25ad45d2585d1058165 (diff) | |
| download | rust-423291f14bbb820265b2bbf33d6fffb044035b86.tar.gz rust-423291f14bbb820265b2bbf33d6fffb044035b86.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/num/mod.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 9deae124829..57b5903c9d3 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4759,15 +4759,38 @@ pub struct ParseIntError { 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)] -enum IntErrorKind { +#[non_exhaustive] +pub enum IntErrorKind { + /// 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 large to store in target integer type. Overflow, + /// Integer is too small to store in target integer type. Underflow, } impl ParseIntError { + /// Outputs the detailed cause of parsing an integer failing. + #[unstable(feature = "int_error_matching", + reason = "it can be useful to match errors when making error messages \ + for integer parsing", + issue = "22639")] + pub fn kind(&self) -> &IntErrorKind { + &self.kind + } #[unstable(feature = "int_error_internals", reason = "available through Error trait and this method should \ not be exposed publicly", |
