-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Add method Result::into_ok #2799
Conversation
This is a small enough change that you could just send a PR and get it done on nightly. |
Co-Authored-By: kennytm <kennytm@gmail.com>
@KrishnaSannasi I've got it lined up, but the collaboration guidance suggests going through an RFC when introducing API additions. It might yet get bogged down in subcommittees, two parties polarized around |
Found a pre-existing Rust issue which proposed nearly exactly what I came up with.
Implementation of rust-lang/rfcs#2799
This is a minor nit, and I really don't want to bikeshed this. But I was very much hoping that with the stabilization of |
@glaebhoerl I'd like the method name to convey the intent of assuring statically the infallibility that may not be available on the generic |
I'm open to a name devoid of uncommon adjectives, like |
To make it really short, but still distinctive, it can be named |
On November 4, 2019 2:25:13 AM PST, Mikhail Zabaluev ***@***.***> wrote:
To make it really short, but still distinctive, it can be named
`into_ok`. As pointed out by @glaebhoerl, the infallibility connotation
of `into` would convey the intent well enough.
I like into_ok as well; that seems quite clear.
|
Bikeshedding in the RFC issue has been most useful.
I think it might be better to call it something that doesn't start with |
To me I also like |
We'd still have to refer to it somehow. |
Did you mean |
Yes, I meant As mentioned above already, from the refactoring facilitation point of view, In general, regarding |
As far as I understand, if someone, somewhere has defined an
Which is what this whole RFC is about :) |
Will, this RFC doesn't help with enforcing a certain code path doesn't contain panics in a general case. It only help with a particular I understand that this RFC provides a workaround to aid people avoid unexpected panic points appearing in their code when doing the code change - and this is good and valuable. It's a very specific case though.
It's distinctive where we have a pattern. I'd argue we should follow a pattern as long as there is one. If we want to change the pattern to ease the audit and search-and-replace - that's a topic worth discussion, but I'd change the existing API too. That'd be a breaking change - not in just the code, but in look-and-feel of the API and it's design (which is a given when optimizing something for audit and search-and-replace). Currently, there's a certain pattern that, just by existing, encourages similar functionality to follow the pattern, otherwise the discoverability of the functionality and logical soundness of the API is hurt. Following pattern is important, because by doing that we can maintain the API as a logically sound set of functionality. Of course it would work both ways, but I'd say the more we deviate from the naming pattern the more chaos we bring to the API. This particular case is definitely not justified enough to break the I agree that it's a shame some calls ( So, to be concrete, I'll give a counter proposal for the name: how about |
That is a very different feature, and out of scope for this RFC. You could create a new RFC for this purpose though.
There is a naming convention when you consume a value and produce a value that was inside the old value, it is usually named I have used a similar convention in my own project, |
If you read carefully, you'll see that that is my point.
That's all good, except |
I would rather not follow |
Well, for what difference it makes, I don't like If we were just thinking about adding a function without thinking about the whole API - the In addition to all the above, there's a practical benefit for discoverability: autocompletion will happily suggest Also, |
Only if the longer name gives some much needed context, which in this case
No, I don't. I generally don't use
It seems like you are confused. This is the api being proposed here does use impl<T> Result<T, !> {
fn into_ok(self) -> T {
match self {
Ok(x) => x,
Err(x) => x, // here `x: !`
}
}
} But with one slight modification, we allow any error type that can be converted to the uninhabited type. We can rely on impl<T, E: Into<!>> Result<T, E> {
fn into_ok(self) -> T {
match self {
Ok(x) => x,
Err(x) => x.into(), // here `x.into(): !`
}
}
}
Yes, because it would only make sense to have |
I'm torn on this one, @remram44. I agree with you, but |
While we're bikeshedding, how about |
Maybe I am too late, but why use a |
@dns2utf8 if you are trying to implement a trait that requires a Also , it is |
@KrishnaSannasi if ERR is ! or Into<!>, then in future probably it will also be Into. Therefore @dns2utf8 suggestion is extension for |
@MikailBag it looks like I misunderstood what @dns2utf8 meant. I don't think that implementing this as |
@KrishnaSannasi Wouldn't that overlap if someone has defined I'm not sure of the ergonomics of the |
@mzabaluev yes, I somehow forgot about blsnket impl interaction. It would definitely be a breaking change to add |
Add method Result::into_ok Implementation of rust-lang/rfcs#2799 Tracking issue #61695
Implementation of rust-lang/rfcs#2799
Add method Result::into_ok Implementation of rust-lang/rfcs#2799 Tracking issue rust-lang#61695
Now that the implementation PR has been merged, should the RFC be merged as well for the good form, or can this simply be closed? |
Closing since the method has been implemented. Tracking issue for stabilization: rust-lang/rust#61695 |
Add method
Result::unwrap_infallible
Result::into_ok
to provide a convenient alternative tounwrap
for convertingResult
values with an uninhabitableErr
type, while ensuring infallibility at compile time.Rendered