Skip to content
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

Update binary_search example to instead redirect to partition_point #95743

Merged
merged 2 commits into from
Apr 11, 2022

Conversation

yaahc
Copy link
Member

@yaahc yaahc commented Apr 6, 2022

Inspired by discussion in the tracking issue for Result::into_ok_or_err: #82223 (comment)

People are surprised by us not providing a Result<T, T> -> T conversion, and the main culprit for this confusion seems to be the binary_search API. We should instead redirect people to the equivalent API that implicitly does that Result<T, T> -> T conversion internally which should obviate the need for the into_ok_or_err function and give us time to work towards a more general solution that applies to all enums rather than just Result such as making or_patterns usable for situations like this via postfix match.

I choose to duplicate the example rather than simply moving it from binary_search to partition point because most of the confusion seems to arise when people are looking at binary_search. It makes sense to me to have the example presented immediately rather than requiring people to click through to even realize there is an example. If I had to put it in only one place I'd leave it in binary_search and remove it from partition_point but it seems pretty obviously relevant to partition_point so I figured the best option would be to duplicate it.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2022
@yaahc yaahc force-pushed the binary-search-clarification branch from 1e1fa1e to c957b80 Compare April 6, 2022 21:24
@rust-log-analyzer

This comment has been minimized.

@yaahc
Copy link
Member Author

yaahc commented Apr 6, 2022

not as sure on this PR anymore since partition_point takes a closure instead of an element. Updating it anyways and gonna let someone else make the call on if they think this is still better.

@yaahc yaahc force-pushed the binary-search-clarification branch from 0bdfffa to 888393e Compare April 7, 2022 01:16
@yaahc yaahc force-pushed the binary-search-clarification branch from 888393e to 0eb0d89 Compare April 7, 2022 01:18
@Mark-Simulacrum
Copy link
Member

I think the closure is fine, and I think this is a good change overall.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 11, 2022

📌 Commit 0eb0d89 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 11, 2022
…r=Mark-Simulacrum

Update binary_search example to instead redirect to partition_point

Inspired by discussion in the tracking issue for `Result::into_ok_or_err`: rust-lang#82223 (comment)

People are surprised by us not providing a `Result<T, T> -> T` conversion, and the main culprit for this confusion seems to be the `binary_search` API. We should instead redirect people to the equivalent API that implicitly does that `Result<T, T> -> T` conversion internally which should obviate the need for the `into_ok_or_err` function and give us time to work towards a more general solution that applies to all enums rather than just `Result` such as making or_patterns usable for situations like this via postfix `match`.

I choose to duplicate the example rather than simply moving it from `binary_search` to partition point because most of the confusion seems to arise when people are looking at `binary_search`. It makes sense to me to have the example presented immediately rather than requiring people to click through to even realize there is an example. If I had to put it in only one place I'd leave it in `binary_search` and remove it from `partition_point` but it seems pretty obviously relevant to `partition_point` so I figured the best option would be to duplicate it.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 11, 2022
…r=Mark-Simulacrum

Update binary_search example to instead redirect to partition_point

Inspired by discussion in the tracking issue for `Result::into_ok_or_err`: rust-lang#82223 (comment)

People are surprised by us not providing a `Result<T, T> -> T` conversion, and the main culprit for this confusion seems to be the `binary_search` API. We should instead redirect people to the equivalent API that implicitly does that `Result<T, T> -> T` conversion internally which should obviate the need for the `into_ok_or_err` function and give us time to work towards a more general solution that applies to all enums rather than just `Result` such as making or_patterns usable for situations like this via postfix `match`.

I choose to duplicate the example rather than simply moving it from `binary_search` to partition point because most of the confusion seems to arise when people are looking at `binary_search`. It makes sense to me to have the example presented immediately rather than requiring people to click through to even realize there is an example. If I had to put it in only one place I'd leave it in `binary_search` and remove it from `partition_point` but it seems pretty obviously relevant to `partition_point` so I figured the best option would be to duplicate it.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 11, 2022
…r=Mark-Simulacrum

Update binary_search example to instead redirect to partition_point

Inspired by discussion in the tracking issue for `Result::into_ok_or_err`: rust-lang#82223 (comment)

People are surprised by us not providing a `Result<T, T> -> T` conversion, and the main culprit for this confusion seems to be the `binary_search` API. We should instead redirect people to the equivalent API that implicitly does that `Result<T, T> -> T` conversion internally which should obviate the need for the `into_ok_or_err` function and give us time to work towards a more general solution that applies to all enums rather than just `Result` such as making or_patterns usable for situations like this via postfix `match`.

I choose to duplicate the example rather than simply moving it from `binary_search` to partition point because most of the confusion seems to arise when people are looking at `binary_search`. It makes sense to me to have the example presented immediately rather than requiring people to click through to even realize there is an example. If I had to put it in only one place I'd leave it in `binary_search` and remove it from `partition_point` but it seems pretty obviously relevant to `partition_point` so I figured the best option would be to duplicate it.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 11, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#95743 (Update binary_search example to instead redirect to partition_point)
 - rust-lang#95771 (Update linker-plugin-lto.md to 1.60)
 - rust-lang#95861 (Note that CI tests Windows 10)
 - rust-lang#95875 (bootstrap: show available paths help text for aliased subcommands)
 - rust-lang#95876 (Add a note for unsatisfied `~const Drop` bounds)
 - rust-lang#95907 (address fixme for diagnostic variable name)
 - rust-lang#95917 (thin_box test: import from std, not alloc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e25bc30 into rust-lang:master Apr 11, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants