Vec::splice()
should explain what happens with an empty range
#135369
Labels
A-collections
Area: `std::collections`
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
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 like3..3
and a non-emptyreplace_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 thatsplice()
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).The text was updated successfully, but these errors were encountered: