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

Add an example to show how to insert item to a sorted vec #63442

Merged
merged 2 commits into from
Aug 11, 2019

Conversation

tesuji
Copy link
Contributor

@tesuji tesuji commented Aug 10, 2019

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 10, 2019
@Mark-Simulacrum
Copy link
Member

@bors r+ rollup=always

@bors
Copy link
Contributor

bors commented Aug 10, 2019

📌 Commit 93839c3 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 Aug 10, 2019
/// let num = 42;
/// let idx = match s.binary_search(&num) {
/// Ok(idx) => idx,
/// Err(idx) => idx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arms could be simplified by using Ok(idx) | Err(idx) => idx

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum Aug 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally find current code clearer than that but r=me with this changed as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be further simplified to let Ok(idx) | Err(idx) = s.binary_search(&num); once we have or-patterns, #54883.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use unwrap_or_else. Do you prefer it instead?

@Mark-Simulacrum
Copy link
Member

The identity closure always irks me but this works too. @bors r+

@bors
Copy link
Contributor

bors commented Aug 10, 2019

📌 Commit 30ba4bd has been approved by Mark-Simulacrum

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Aug 11, 2019
…k-Simulacrum

Add an example to show how to insert item to a sorted vec

Closes rust-lang#61684
cc rust-lang#61742
r? @Mark-Simulacrum, @jonas-schievink
bors added a commit that referenced this pull request Aug 11, 2019
Rollup of 8 pull requests

Successful merges:

 - #61969 (Add #[repr(transparent)] for several types)
 - #62108 (Use sharded maps for queries)
 - #63149 (resolve: Populate external modules in more automatic and lazy way)
 - #63346 (Lint on some incorrect uses of mem::zeroed / mem::uninitialized)
 - #63433 (Miri shouldn't look at types)
 - #63440 (rename RUST_CTFE_BACKTRACE to RUSTC_CTFE_BACKTRACE)
 - #63442 (Add an example to show how to insert item to a sorted vec)
 - #63459 (syntax: account for CVarArgs being in the argument list.)

Failed merges:

r? @ghost
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Aug 11, 2019
…k-Simulacrum

Add an example to show how to insert item to a sorted vec

Closes rust-lang#61684
cc rust-lang#61742
r? @Mark-Simulacrum, @jonas-schievink
bors added a commit that referenced this pull request Aug 11, 2019
Rollup of 8 pull requests

Successful merges:

 - #61969 (Add #[repr(transparent)] for several types)
 - #63346 (Lint on some incorrect uses of mem::zeroed / mem::uninitialized)
 - #63433 (Miri shouldn't look at types)
 - #63440 (rename RUST_CTFE_BACKTRACE to RUSTC_CTFE_BACKTRACE)
 - #63441 (Derive Debug for CrateInfo)
 - #63442 (Add an example to show how to insert item to a sorted vec)
 - #63453 (rustdoc: general cleanup)
 - #63464 (Copy ty::Instance instead of passing by reference)

Failed merges:

r? @ghost
@bors bors merged commit 30ba4bd into rust-lang:master Aug 11, 2019
@tesuji tesuji deleted the vec-bin-search-insert branch August 12, 2019 01:13
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
6 participants