Tracking Issue for result_swap
#81322
Labels
A-result-option
Area: Result and Option combinators
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Feature gate:
#![feature(result_swap)]
This is a tracking issue for
result_swap
I propose the addition of a
swap
method for theResult
type that would basically turn anOk
into anErr
and the other way around.Motivation
This would obviously allow more straightforward code when one need to propagate the success type of a function as an error.
Used with the
Result
constructors that are present onOption
, this method also can come in handy.Note that this second case could also be fixed with something like
err_or
(being discussed here #80190).Steps
Result::swap
and tests #81323)Unresolved Questions
swap
may be confused with the already-used semantic ofmem::swap
orslice::swap
which both have a slightly different meaning. The alternative I had for this matter was the namenot
(the function basically inverts the meaning of theResult
) but I think it makes it even more confusing.Option::swap
equivalent that would mapSome(old_value)
toNone
andNone
toSome(new_value)
wherenew_value
is a parameter ofOption::swap
? Such a function would probably require aOption::swap_with
counterpart that takes aFnOnce() -> T
.The text was updated successfully, but these errors were encountered: