-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement Default
for Result<(), E>
#86065
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @scottmcm (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. |
Thanks for the PR, @IQBigBang! I think, however, that this change ought to have an RFC. Trait implementations cannot go in as unstable (for technical reasons), so there's no opportunity to experiment with this before stabilization. And this is a controversial area, with many explorations of related features (such as rust-lang/rfcs#2120), so the extra discussion of motivations and tradeoffs would be valuable. Some things an RFC might discuss:
(Official libs folks: of course you should feel free to contradict me here if you disagree.) |
The job Click to see the possible cause of the failure (guessed by this bot)
|
I noticed you have an IRLO thread open at https://internals.rust-lang.org/t/suggestion-pre-rfc-implement-default-for-result/14843?u=scottmcm I'm going to close this for now, pending outcome of discussions that happen there and feedback from libs folks. One thing to add to my previous post: you should probably get an informal "we'd be interested in considering that" from the libs team before putting in the work to draft an RFC, just to make sure that you don't spend the effort unnecessarily. |
Implement the
Default
trait forResult<(), E>
.It makes sense for
Result<(), E>
to implement this as a counterpart ofSome(T)
, because bothOk(())
andNone
signify the absence of a value.It also goes hand in hand with the common Rust idiom of calling several functions which return a
Result
: