Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upString/Vec::splice(RangeArgument, IntoIterator) #1432
Conversation
SimonSapin
referenced this pull request
Dec 28, 2015
Closed
Tracking issue for `str_char` stabilization #27754
This comment has been minimized.
This comment has been minimized.
|
Any reason you don't return an iterator that consumes the removed elements like splice? I'd also just call it Second, you can fall back on allocating temporary storage and copying twice if |
This comment has been minimized.
This comment has been minimized.
|
Both good points. |
This comment has been minimized.
This comment has been minimized.
|
It looks like this functionality already exists! http://bluss.github.io/arrayvec/doc/odds/vec/trait.VecExt.html#tymethod.splice |
SimonSapin
added some commits
Dec 29, 2015
This comment has been minimized.
This comment has been minimized.
|
nrc
added
the
T-libs
label
Jan 4, 2016
This comment has been minimized.
This comment has been minimized.
dbrodie
commented
Jan 5, 2016
|
I think this is covered in #1253, just, as commented, should be generalized to Vec as well. |
Gankro
self-assigned this
Jan 7, 2016
SimonSapin
changed the title
String/Vec::replace_range(RangeArgument, IntoIterator)
String/Vec::splice(RangeArgument, IntoIterator)
Feb 12, 2016
SimonSapin
added some commits
Feb 12, 2016
This comment has been minimized.
This comment has been minimized.
|
I’ve updated the RFC to incorporate some feedback (rename to @alexcrichton Could the libs team discuss this? Is it desired in |
aturon
assigned
aturon
and unassigned
Gankro
Feb 12, 2016
This comment has been minimized.
This comment has been minimized.
|
This all seems pretty reasonable to me, and the libs team process for this is to:
So along those lines anyone can always discuss this! If @aturon or anyone else on the libs team thinks this is ready for FCP then we'll likely move it in. |
This comment has been minimized.
This comment has been minimized.
dbrodie
commented
Feb 14, 2016
|
Another possibility is to add this as functionality to the Drain iterator. (This was @bluss's idea when I discussed it with him). Basically having something like: FWIW there are quite a few languages which have this operation as a first class feature, for example, Python ( |
This comment has been minimized.
This comment has been minimized.
|
Indeed, now that this new method was changed to return an iterator I think it’s equivalent to |
This comment has been minimized.
This comment has been minimized.
tikue
commented
Feb 16, 2016
|
Would this be a duplicate fn if |
This comment has been minimized.
This comment has been minimized.
|
Would |
This comment has been minimized.
This comment has been minimized.
tikue
commented
Feb 16, 2016
|
I'm not sure which parameter you mean, but I was imagining this (I very well may be wrong here!): Given:
it would look like:
|
This comment has been minimized.
This comment has been minimized.
tikue
commented
Feb 16, 2016
|
Ah, but I see splice is supposed to return the spliced-out slice. Perhaps that's just an oversight in the |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Feb 16, 2016
|
The IndexAssign RFC /pull/1129 doesn't actually propose adding any operations to slices using IndexAssign. |
This comment has been minimized.
This comment has been minimized.
tikue
commented
Feb 16, 2016
|
True, but that could be revisited. It certainly seems like it's be nice. |
This comment has been minimized.
This comment has been minimized.
|
|
alexcrichton
added
the
final-comment-period
label
Mar 3, 2016
This comment has been minimized.
This comment has been minimized.
ollie27
commented
Mar 3, 2016
|
How about adding two methods |
This comment has been minimized.
This comment has been minimized.
|
@ollie27 In the current proposal, you don't have to consume the iterator, you just have to drop it. |
This comment has been minimized.
This comment has been minimized.
ollie27
commented
Mar 4, 2016
|
Well that's still an extra thing you have to do. |
This comment has been minimized.
This comment has been minimized.
tikue
commented
Mar 4, 2016
|
Drops are automatic. You don't have to explicitly do anything.
|
This comment has been minimized.
This comment has been minimized.
ollie27
commented
Mar 4, 2016
|
Ah good point, I was thinking of assigning the result to a variable for some reason. |
bluss
reviewed
Mar 4, 2016
| } | ||
| } | ||
| struct Splice<I: IntoIterator> { |
This comment has been minimized.
This comment has been minimized.
bluss
Mar 4, 2016
I think this should be Iterator else it won't work out. But that's a technicality.
This comment has been minimized.
This comment has been minimized.
bluss
commented
Mar 4, 2016
|
The new flexible length semantics seem proportionally complex to me. |
This comment has been minimized.
This comment has been minimized.
|
@bluss I don’t understand your last comment. I guess flexible length refers to the iterator of new values not having to be the same length as the range it replaces. But what does proportionally complex mean? |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Mar 4, 2016
|
splice found a nice way to solve it for any iterator I think. I just mean that splice is simple for good input (exact size-ish) and a bit more involved for the fallback cases, but it's not too complex. Complexity was my main worry with the expanded scope with non-exact size iterators. |
alexcrichton
referenced this pull request
Mar 17, 2016
Closed
Tracking issue for {Vec,String}::splice #32310
This comment has been minimized.
This comment has been minimized.
|
This RFC was discussed yesterday during libs triage, and the decision was to merge. We discussed whether we want APIs like this to run wild as it's unclear if the API of types like Thanks for the RFC @SimonSapin |
This comment has been minimized.
This comment has been minimized.
|
Tracking issue: rust-lang/rust#32310 |
alexcrichton
merged commit ae0b0cd
into
rust-lang:master
Mar 17, 2016
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Did the libs team discuss unresolved questions? In particular, when to consume the input iterator. |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin We didn't discuss that in depth in the meeting (and in general are OK tweaking this point prior to stabilization). From my perspective, I think it makes the most sense to consume on drop, given that there isn't necessarily a direct relationship between the number of items being drained and those being incorporated. (That is, if you had an interleaving semantics, in general interleaving would only happen for some prefix.) It seems simpler and more consistent to just do them all at once after the drop. For the record, I'm just a little uncomfortable with so much of the action being tied to |
This comment has been minimized.
This comment has been minimized.
|
I agree that doing so much in |
SimonSapin commentedDec 28, 2015
•
edited by mbrubeck
Add a
replace_slicemethod toVec<T>andStringremoves a range of elements,and replaces it in place with a given sequence of values.
The new sequence does not necessarily have the same length as the range it replaces.
Rendered.