Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MutableVector::mut_split(self, pred) -> DoubleEndedIterator<&mut [T]> #10757

Merged
merged 2 commits into from
Dec 3, 2013

Conversation

TeXitoi
Copy link
Contributor

@TeXitoi TeXitoi commented Dec 1, 2013

I've renamed MutableVector::mut_split(at) to MutableVector::mut_split_at(at) to be coherent with ImmutableVector. As specified in the commit log, The size_hint method is not optimal because of #9629.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 2, 2013

Sorry, I rebased before seeing @cmr r+

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 2, 2013

The tests are buggy, they don't compile. I'll correct that when I can.

@alexcrichton
Copy link
Member

I would expect mut_split to take an integer and this function to rather be named something like mut_split_when, but this is also going a little bit into the territory of me questioning whether it should be included in libstd.

Is there a common use case for an iterator like this?

@alexcrichton
Copy link
Member

I was also a little confused when reading the documentation about whether the element the predicate is run on is included in the slice of the iterator or not (I think this needs some more explicit working in the function documentation).

@Kimundi
Copy link
Member

Kimundi commented Dec 2, 2013

@alexcrichton The split (and with this PR mut_split) iterators on vectors work like this because they copy the API on strings: "a b c d".split(char::is_whitespace) for example - Granted, it might be more obvious there.

However, given the fact that there are multiple ways you could split a slice: At an index, at places where a predicate holds, at chars for strings etc, it is indeed uncertain how the API should look, and what name to give the functions - that seems like a broader issue though. Short term, making split and mut_split consistent by renaming either seems to be higher priority to me.

As an aside, I'm planning to improve and unify the string API for finding a contained pattern in general, and would then likely try to port whatever I come up with to vectors.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 2, 2013

for mut_split -> mut_split_when (or mut_split_with?), I can do the change, but I'll have to change ImmutableVector::split(). But as @Kimundi said, maybe it's better to let it like that for now.

For the documentation, it's the same as ImmutableVector::split(). I can update the two.

I needed this iterator during my shootout-reverse-complement.rs rewrite, that is basically reversing a &mut [u8] sepparated by >. Maybe it can be useful to modify binary stream (as putting uppercase some fields of csv file).

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 2, 2013

Tests fixed (pass here) and split doc clarified.

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 3, 2013

@alexcrichton Remarks? OK?

@alexcrichton
Copy link
Member

looks good to me, could you squash the last two commits together?

…[T]>

This method is the mutable version of ImmutableVector::split.  It is
a DoubleEndedIterator, making mut_rsplit irrelevent.  The size_hint
method is not optimal because of rust-lang#9629.

At the same time, clarify *split* iterator doc.
@TeXitoi
Copy link
Contributor Author

TeXitoi commented Dec 3, 2013

@alexcrichton squashed.

bors added a commit that referenced this pull request Dec 3, 2013
I've renamed `MutableVector::mut_split(at)` to `MutableVector::mut_split_at(at)` to be coherent with ImmutableVector.  As specified in the commit log, The `size_hint` method is not optimal because of #9629.
@bors bors closed this Dec 3, 2013
@bors bors merged commit 44fc3c6 into rust-lang:master Dec 3, 2013
@TeXitoi TeXitoi deleted the mut-split-iter branch April 21, 2014 22:11
flip1995 pushed a commit to flip1995/rust that referenced this pull request May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants