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

StrSlice should have split_at #18063

Closed
Manishearth opened this issue Oct 15, 2014 · 14 comments
Closed

StrSlice should have split_at #18063

Manishearth opened this issue Oct 15, 2014 · 14 comments
Labels
A-collections Area: `std::collection`

Comments

@Manishearth
Copy link
Member

ImmutableSlice has a split_at method. This would probably be useful for StrSlice as well.

(It might be a good idea to share some of the other methods between StrSlice and ImmutableSlice too)

@kmcallister kmcallister added the A-collections Area: `std::collection` label Jan 16, 2015
@Diggsey
Copy link
Contributor

Diggsey commented Jan 16, 2015

It would have to make sure not to split the string across a multi-byte codepoint.

@Manishearth
Copy link
Member Author

In the context of Rust strings n is de facto the Unicode-safe index, not the byte index.

@Diggsey
Copy link
Contributor

Diggsey commented Jan 17, 2015

That would make it inconsistent with the other methods on "str", which use byte indices unless explicitly specified otherwise by the presence of "chars" in the method name.

It would also introduce a hidden complexity cost, making the string version of "split_at" be O(n) instead of O(1) - the obvious use-case of splitting a string at multiple places then becomes O(n^2), which is unnacceptable for many applications.

@Manishearth
Copy link
Member Author

split_at_char then.

@djmally
Copy link
Contributor

djmally commented Mar 2, 2015

I'll take a look into this, if no one else is already.

@Manishearth
Copy link
Member Author

Sounds good. @gankro does this need an RfC?

@Gankra
Copy link
Contributor

Gankra commented Mar 2, 2015

Uh, what are the traits called now?

@djmally
Copy link
Contributor

djmally commented Mar 2, 2015

That was going to be my next question, I think StrSlice is no longer a trait as of 1.0alpha

@djmally
Copy link
Contributor

djmally commented Apr 1, 2015

Does this still need to be done (i.e. has the trait been renamed), or should this be closed?

@steveklabnik
Copy link
Member

@steveklabnik
Copy link
Member

(that trait no longer exists, and this is an inherent impl now)

@bluss
Copy link
Member

bluss commented May 7, 2015

.split_at() on &str would be very useful. To be consistent it would use a byte offset though. I'd like this.

@steveklabnik steveklabnik reopened this May 7, 2015
@steveklabnik
Copy link
Member

oh whoops! slice != str slice...

@huonw
Copy link
Member

huonw commented Jan 5, 2016

@huonw huonw closed this as completed Jan 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collection`
Projects
None yet
Development

No branches or pull requests

8 participants