-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @bluss (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
oops, I think I am going to need more help than I thought with this one. |
cc @rust-lang/libs |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I can't work out what the problem is. Is this just travis falling over or is it a problem with my code? @TimNN |
Looking at the raw log, it looks like |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Before doing more work, maybe wait for someone from the libs team to respond? As far as I know, these sorts of types are generally very intentionally not fully public, to allow adding more information later. That's particularly important for ParseFloatError whose ErrorKind enum is far, far less helpful than it could be. #22639 has a point, but could be solved by just making ErrorKind public and |
@rkruppe Thanks for the information. It does sound like |
Why is this more useful than |
@SimonSapin The messages made by Having ParseIntError as public will stop ugly patterns like this example @amosbatto gave in #22639
|
@ethanboxx Quick nit: |
@eddyp At the end of the day, that code example would never pass a review even if We need it to be able to match the error with enum matching for this to be nice clean code. |
Exposing the enum sounds ok (especially with |
That sounds all right. Before I try it can you please give me a reason why a new field may be added to |
This is being very conservative, quite possibly we’ll never change this type again. But one example could be providing further details, for example in the |
Would it not be better to store things like "what digit was invalid" in the enum. #[non_exhaustive]
pub enum ParseIntError {
Empty,
InvalidDigit,
Overflow,
Underflow,
} would become #[non_exhaustive]
pub enum ParseIntError {
Empty,
InvalidDigit(char),
Overflow,
Underflow,
} or to preserve backward compatibility #[non_exhaustive]
pub enum ParseIntError {
Empty,
SomeInvalidDigit(char),
/// `InvalidDigit` is no longer ever constructed
InvalidDigit,
Overflow,
Underflow,
} A new struct field sounds confusing to me. Why would it be better than this method? @SimonSapin |
@ethanboxx I think you meant @eddyb |
It wouldn't break literally all code that matches on |
@eddyp Thank you for taking your time correcting my mistake. |
@sfackler @SimonSapin I didn't think of that. Thank you for the suggestion. I have now implemented the accessor method. What do you think now? |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Is there a reason why activity on this thread has stopped? I would like to know if my code has any ways in which it can be improved. It is fine if this is a low priority, but I would like to know if it is. |
Triage; @SimonSapin Hello, have been able to get back to this PR? |
Sorry for the delay. Since neither type is |
@SimonSapin I think that is the correct thing to do. I have updated the code to do what you suggested. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
#[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)] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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!
@bors r+ |
📌 Commit 121e5e8 has been approved by |
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.
☀️ Test successful - status-appveyor, status-travis |
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.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.