Skip to content

Conversation

@cod10129
Copy link
Contributor

@cod10129 cod10129 commented Jan 11, 2025

This example clearly showcases how splice can be used to insert multiple elements efficiently at an index into a vector.

Fixes #135369.

The added example:

Using splice to insert new items into a vector efficiently at a specific position indicated by an empty range:

let mut v = vec![1, 5];
let new = [2, 3, 4];
v.splice(1..1, new);
assert_eq!(v, [1, 2, 3, 4, 5]);

@rustbot label A-docs A-collections

@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-collections Area: `std::collections` labels Jan 11, 2025
Add an example for using splice to insert multiple elements efficiently into a vector.
@tgross35
Copy link
Contributor

Thanks for the change, lgtm.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 14, 2025

📌 Commit b11f87a has been approved by tgross35

It is now in the queue for this repository.

@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 Jan 14, 2025
@bors bors merged commit bf228a8 into rust-lang:master Jan 14, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 14, 2025
@cod10129 cod10129 deleted the vec-splice-doc branch January 14, 2025 13:46
@cod10129 cod10129 restored the vec-splice-doc branch January 14, 2025 13:47
@cod10129 cod10129 deleted the vec-splice-doc branch January 14, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-collections Area: `std::collections` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vec::splice() should explain what happens with an empty range

5 participants