Add a Result::into_ok_or_err method to extract a T from Result<T, T>#80572
Add a Result::into_ok_or_err method to extract a T from Result<T, T>#80572bors merged 4 commits intorust-lang:masterfrom
Result::into_ok_or_err method to extract a T from Result<T, T>#80572Conversation
|
r? @shepmaster (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
|
|
I'm comfortable renaming if desired. I think I don't care that much about the name so long as the functionality is available under some name though. Another suggestion I got was implementing |
library/core/src/result.rs
Outdated
There was a problem hiding this comment.
Note that:
- I can't use the fancy intradoc links stuff here for reasons that only @jyn514 comprehends.
- Apparently primitives are only documented in std (No documentation for primitives in
core#80334 or something), so I have to link it instd.
That said, I'm also okay with getting rid of these links entirely if that's desirable.
There was a problem hiding this comment.
You can now use intra-doc links here!
| /// [binary_search]: ../../std/primitive.slice.html#method.binary_search | |
| /// [binary_search]: slice::binary_search |
There was a problem hiding this comment.
Actually, better yet you can change the part above that has the link to just [`slice::binary_search`] and remove this line.
There was a problem hiding this comment.
You can now use intra-doc links here!
No, the bootstrap bump hasn't happened yet. Intra-doc pointers landed in #80181, which is in 1.51, which is still in nightly.
There was a problem hiding this comment.
Dang, I always forget about the bootstrap bump :(
library/core/src/result.rs
Outdated
There was a problem hiding this comment.
Binary search is the primary reason I've wanted similar, but I've also seen people want to use it in procedural macros where you use a TokenStream for success and failure cases.
This seems reasonable to add as an unstable feature.
|
Naming consistency with |
|
☔ The latest upstream changes (presumably #81417) made this pull request unmergeable. Please resolve the merge conflicts. |
|
r? @m-ou-se |
|
We briefly discussed this in the libs team meeting last week, and agreed this is a function we should have. There was some discussion on the name, but felt comfortable landing this as Can you open a tracking issue? Thanks! |
|
|
Result::ok_or_err method to extract a T from Result<T, T>Result::ok_or_err~~ Result::into_ok_or_err method to extract a T from Result<T, T>
Result::ok_or_err~~ Result::into_ok_or_err method to extract a T from Result<T, T>Result::into_ok_or_err method to extract a T from Result<T, T>
|
@bors r+ rollup |
|
📌 Commit 404da0b has been approved by |
Rollup of 8 pull requests Successful merges: - rust-lang#77728 (Expose force_quotes on Windows.) - rust-lang#80572 (Add a `Result::into_ok_or_err` method to extract a `T` from `Result<T, T>`) - rust-lang#81860 (Fix SourceMap::start_point) - rust-lang#81869 (Simplify pattern grammar, improve or-pattern diagnostics) - rust-lang#81898 (Fix debug information for function arguments of type &str or slice.) - rust-lang#81972 (Placeholder lifetime error cleanup) - rust-lang#82007 (Implement reborrow for closure captures) - rust-lang#82021 (Spell out nested Self type in lint message) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
When updating code to handle the semi-recent deprecation of
compare_and_swapin favor ofcompare_exchange, which returnsResult<T, T>, I wanted this. I've also wanted it with code usingslice::binary_searchbefore.The name (and perhaps the documentation) is the hardest part here, but this name seems consistent with the other Result methods, and equivalently memorable.