Uh oh!
There was an error while loading. Please reload this page.
Implement Vec::drain from RFC 574 - #24781
Conversation
rust-highfive
commented
Apr 24, 2015
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
brson
commented
Apr 24, 2015
r? @aturon |
There was a problem hiding this comment.
Stylistically the compiler doesn't tend to put an import-per-line like this but instead use multiple use statements.
There was a problem hiding this comment.
One line with {RangeFull, Range, ..} for all the ranges would be the usual style then?
There was a problem hiding this comment.
Indeed! The wrapping (to a new import) just happens if it runs over 80 chars
bluss
commented
Apr 25, 2015
I've addressed all review comments, thank you @alexcrichton! Introducing this as unstable gives us leeway to fix it up later, what we could change:
|
There was a problem hiding this comment.
On second though, could you apply just one of these stability attributes to the module itself? The instability should be inherited. Additionally, could you give this a name like collections_range as well?
alexcrichton
commented
Apr 27, 2015
Looks great to me, thanks @bluss! After some minor refinements of the feature names here I think this is good to go! |
bluss
commented
Apr 27, 2015
I'm excited. I'm working on checking that it compiles and then squashing it together. |
alexcrichton
commented
Apr 27, 2015
Thanks! Lemme know when it's ready to go and I'll r+ |
RangeArgument is introduced as unstable under the feature(collections_range)
bluss
commented
Apr 27, 2015
There, it should be ready. I could have missed something, haven't added new feature flags before. |
alexcrichton
commented
Apr 27, 2015
bors
commented
Apr 28, 2015
⌛ Testing commit 447ef06 with merge dc19940... |
bors
commented
Apr 28, 2015
💔 Test failed - auto-mac-64-opt |
Old `.drain()` on vec is performed using `.drain(..)` now. `.drain(range)` is unstable and under feature(collections_drain) [breaking-change]
bluss
commented
Apr 28, 2015
Fixed that test. |
alexcrichton
commented
Apr 28, 2015
bors
commented
Apr 28, 2015
Implement Vec::drain(\<range type\>) from rust-lang/rfcs#574, tracking issue #23055. This is a big step forward for vector usability. This is an introduction of an API for removing a range of *m* consecutive elements from a vector, as efficently as possible. New features: - Introduce trait `std::collections::range::RangeArgument` implemented by all four built-in range types. - Change `Vec::drain()` to use `Vec::drain<R: RangeArgument>(R)` Implementation notes: - Use @gankro's idea for memory safety: Use `set_len` on the source vector when creating the iterator, to make sure that the part of the vector that will be modified is unreachable. Fix up things in Drain's destructor — but even if it doesn't run, we don't expose any moved-out-from slots of the vector. - This `.drain<R>(R)` very close to how it is specified in the RFC. - Introduced as unstable - Drain reuses the slice iterator — copying and pasting the same iterator pointer arithmetic again felt very bad - The `usize` index as a range argument in the RFC is not included. The ranges trait would have to change to accomodate it. Please help me with: - Name and location of the new ranges trait. - Design of the ranges trait - Understanding Niko's comments about variance (Note: for a long time I was using a straight up &mut Vec in the iterator, but I changed this to permit reusing the slice iterator). Previous PR and discussion: #23071
bors
commented
Apr 29, 2015
Stebalien
commented
Apr 30, 2015
So I know I'm starting to sound like a broken record but... use std::collections::Bound;traitBounds{fnstart(&self) -> Bound<&T>;fnend(&self) -> Bound<&T>;}impl<T>BoundsforRange<T>{fnstart(&self) -> Bound<&T>{Bound::Included(&self.start)}fnstart(&self) -> Bound<&T>{Bound::Excluded(&self.end)}}// ...I suggest adding an |
bluss
commented
Apr 30, 2015
I agree it's not ready for stabilization. Specifically the design of the trait over ranges, and then we should impl drain for more collections to see how the API holds up. |
glaebhoerl
commented
May 6, 2015
|
Implement Vec::drain() from rust-lang/rfcs#574, tracking issue #23055.
This is a big step forward for vector usability. This is an introduction of an API for removing a range of m consecutive elements from a vector, as efficently as possible.
New features:
std::collections::range::RangeArgumentimplemented by all four built-in range types.Vec::drain()to useVec::drain<R: RangeArgument>(R)Implementation notes:
set_lenon the source vector when creating the iterator, to make sure that the part of the vector that will be modified is unreachable. Fix up things in Drain's destructor — but even if it doesn't run, we don't expose any moved-out-from slots of the vector..drain<R>(R)very close to how it is specified in the RFC.usizeindex as a range argument in the RFC is not included. The ranges trait would have to change to accomodate it.Please help me with:
Previous PR and discussion: #23071