Skip to content

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

Closed
@djeedai

Description

Location

https://doc.rust-lang.org/std/vec/struct.Vec.html#method.splice

Summary

As explained in this SO answer, which I assume to be correct, using Vec::splice() with an empty range like 3..3 and a non-empty replace_with argument allows inserting multiple values at once at the index specified by, I think, the range start. But this is not documented, and I don't think it's necessarily trivial for everyone (I had to lookup that SO answer to confirm). I think an example of inserting multiple values without removing any would be beneficial for understanding that splice() is the right tool for that job (and you don't need anything more complicated via iterators and loops or whatnot, like others on SO suggested).

Metadata

Assignees

Labels

A-collectionsArea: `std::collection`A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions