-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add an example to show how to insert item to a sorted vec #63442
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
23f34f5
to
93839c3
Compare
@bors r+ rollup=always |
📌 Commit 93839c3 has been approved by |
src/libcore/slice/mod.rs
Outdated
/// let num = 42; | ||
/// let idx = match s.binary_search(&num) { | ||
/// Ok(idx) => idx, | ||
/// Err(idx) => idx, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
The identity closure always irks me but this works too. @bors r+ |
📌 Commit 30ba4bd has been approved by |
…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
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
…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
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
Closes #61684
cc #61742
r? @Mark-Simulacrum, @jonas-schievink