Closed
Description
The type signature of Result::map_or_else
:
pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U where
F: FnOnce(T) -> U,
D: FnOnce(E) -> U,
Note how default
is the function that gets applied to the Err
variant. Then, the docstring (emphasis mine):
Maps a
Result<T, E>
toU
by applying a fallback function to a containedErr
value, or a default function to a containedOk
value.
I think this is a very unfortunate choice of words and should be changed.
Activity
jyn514 commentedon Aug 21, 2021
@orlp are you interested in making a PR to fix it? :) there are instructions in https://rustc-dev-guide.rust-lang.org/getting-started.html#building-and-testing-stdcorealloctestproc_macroetc
orlp commentedon Aug 21, 2021
I could, but I think I'd prefer to bikeshed a bit first as to how it should be described.
MightyPork commentedon Aug 22, 2021
To me these functions are so confusing that I practically never use them, the arguments are in the wrong order ... as repeatedly noted in both the tracking issue and stabilization PR that added it. It can't be changed, of course :/
I rather like the way it's documented in the corresponding method on
Option
: https://doc.rust-lang.org/std/option/enum.Option.html#method.map_or_elsemdsn commentedon Aug 27, 2021
How about
It explains in the same order as the function name (
ok_or_else
) and doesn't overload the meaning of "default" in the context of the unfortunate function argument.orlp commentedon Sep 9, 2021
Made a pull request using @mdsn 's suggestion, only replacing "applying
default
" with "applying functiondefault
" to be consistent with the earlier part of the sentence.Rollup merge of rust-lang#88772 - orlp:result-map-or-else-docfix, r=y…
Rollup merge of rust-lang#88772 - orlp:result-map-or-else-docfix, r=y…
Rollup merge of rust-lang#88772 - orlp:result-map-or-else-docfix, r=y…