-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Option::into_result #17469
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 Option::into_result #17469
Conversation
cc @aturon - not sure what stability attribute to put on this. |
Thanks, I'd been wanting to add this API. Please mark as experimental for now. |
I'm wondering about the rationale for returning a |
6f4061b
to
0a21129
Compare
You can always swap out the error type by composing with Pushed a version with the stability attribute. |
Right. It's a question of what we expect to be the common usage. The I agree that we may want a variant with a closure, but for now adding a parameter for the error component seems like an improvement: // compare:
opt.into_result()
opt.into_result(())
// compare:
opt.into_result().map_err(|_| MyError)
opt.into_result(MyError) Also, I'd like to think a bit about the name of this method. The corresponding Finally, we may be able to use a trick from the collections reform RFC to drop all of the closure variants. |
Thinking about it it's interesting that I don't feel the need to prefix We could possibly drop the |
|
@sfackler So, That said, I think In any case, I'm glad to land this with either name as |
0a21129
to
856f19d
Compare
Updated |
These are the inverses of `Result::ok` and help to bridge `Option` and `Result` based APIs.
856f19d
to
0c8878d
Compare
This is the inverse of `Result::ok` and helps to bridge `Option` and `Result` based APIs.
fix: use ItemInNs::Macros to convert ModuleItem to ItemInNs fix rust-lang#17425. When converting `PathResolution` to `ItemInNs`, we should convert `ModuleDef::Macro` to `ItemInNs::Macros` to ensure that it can be found in `DefMap`.
This is the inverse of
Result::ok
and helps to bridgeOption
andResult
based APIs.