-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add unwrap_or_default
method to Result
#37299
Add unwrap_or_default
method to Result
#37299
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
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.
Nice! I've wanted to use this (but needed to write .unwrap_or_else(Default::default)
instead) :)
/// | ||
/// Convert a string to an integer, turning poorly-formed strings | ||
/// into 0 (the default value for integers). `parse` converts | ||
/// a string to any other type that implements `FromStr`, returning an |
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.
It'd be nice to link FromStr
to the FromStr
docs page
/// assert_eq!(0, bad_year); | ||
/// ``` | ||
#[inline] | ||
#[stable(feature = "rust1", since = "1.0.0")] |
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.
Is this stable
attribute correct? I'd expect it to have since = "1.14.0"
(I don't know where feature names are defined).
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.
This should probably start as unstable
.
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.
instruction: Should be unstable, no version number. Pick a new feature name, for example "result_unwrap_or_default". Use issue = "0"
in the unstable tag; an issue can be opened and filled in when this PR has been cleared for inclusion.
Pros:
Cons:
|
Thanks for the PR @devonhollowood! I agree that we'll want to start out here with an Also thanks for the pros/cons list @leodasvacas! I personally feel that this is filling a gap where |
Apologies about the stability thing. Somewhat embarrassingly, that line of code got caught up when I was copying the documentation example from Incidentally, is there a faster way to build the docs than |
Looks great to me, thanks! We'll want to change the issue number of 0 to something real eventually, but for now that's fine. In the meantime... @rfcbot fcp merge |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Good addition, thanks. |
🔔 This is now entering its final comment period, as per the review above. 🔔 psst @alexcrichton, I wasn't able to add the |
@bors: r+ |
📌 Commit 5d31a81 has been approved by |
…xcrichton Add `unwrap_or_default` method to `Result` Fixes #37025
…tracking-issue, r=alexcrichton Add tracking issue number to Result::unwrap_or_default unstable annotation. Implemented in rust-lang#37299. Tracking issue: rust-lang#37516.
Fixes #37025