-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue for Result::into_ok #61695
Copy link
Copy link
Open
Labels
A-result-optionArea: Result and Option combinatorsArea: Result and Option combinatorsB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-result-optionArea: Result and Option combinatorsArea: Result and Option combinatorsB-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is (now) a tracking issue for
https://doc.rust-lang.org/nightly/std/result/enum.Result.html#method.into_ok
https://doc.rust-lang.org/nightly/std/result/enum.Result.html#method.into_err
#![feature(unwrap_infallible)]I would like to propose adding a
unwrap_infallibleassociated function tocore::result::Result. The purpose is to convertResult<T, core::convert::Infallible>to aT, as the error case is impossible.The implementation would basically be:
An example use-case I have is a wrapper type with generic value verification, like
Handle<T:Verify>. Some verifications can fail, but some can not. When verification is infallible, aResult<Handle<T>, Infallible>will be returned.Since some can fail, the
Handletype implementsTryFromand notFrom. Because of the blanket implementation ofTryFromfor all types implementingFrom, I can't additionally add aFromconversion for the infallible cases. This blanket implementation makes sense, as it allows an API to take aT: TryFromand handle all possible conversions, even infallible ones.But for the API consumer it would be beneficial to be able to go from an infallible
Result<T, Infallible>to a plainTwithout having to manually match or useexpect. The latter is shorter and chainable, but has the disadvantage that it will still compile when the types are changed and the conversion is no longer infallible.It might be that there is a different solution to infallible conversions via
TryFromin the future, for example via specialization. I believe that having anunwrap_infalliblewould still be beneficial in many other cases where generically fallible actions can be infallible in certain situations. One example is when working with a library that is based on fallible operations with a user supplied error type, but where the specific implementation from the user is infallible.I'd be happy to work on a PR for this if it's acceptable to add, though I might require some guidance with regards to stability attributes, feature flags and so on. It's a bit hard to find information on that, and experimentation is costly as it takes me a while to complete a
./x.py test src/libcore:)