-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Possible Vec::split improvement #49036
Copy link
Copy link
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Hi guys! The other day I was working on something where I had some
Vec<u8>data and wanted to split on two consecutive bytes. Normally with strings I can just do:But for
Vec<u8>it only accepts a closure rather than a Pattern type, so it's not very easy to split on consecutive bytes. I noticed thatString::splitcoerces closures and strings into Patterns that it uses to do the split. Do you think it would be possible (or even a good idea) to modifyVec::splitandslice::splitto accept any Pattern type and implement a new searcher for any PartialEq type? That would be pretty nice. Then we could do things like:Which is useful if you're dealing with lots of bytes that may or may not be valid UTF-8.
And just generally it makes sense to me that if
String::splitaccepts a&str, thatVec<T>::splitwould accept a&[T].Maybe I'm missing something obvious that makes this impossible since I imagine someone would've done it already if it were possible.