-
Notifications
You must be signed in to change notification settings - Fork 19
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 str::reverse
method for in place string reversal
#353
Comments
I think we need something more compelling than this for Note that |
Just in case, am I right that since |
Yeah, it looks like usually, users expect to reverse graphemes, not the codepoints. Although it may be useful to have idiomatic alternative to |
My favourite example for why [src/main.rs:2:5] "🇸🇪".chars().rev().collect::() = "🇪🇸" I think the common places you might want this are leetcode style things, where rust-lang/rust#110998 might be the better way, since |
Proposal
Problem statement
Currently, to reverse a UTF-8 string you need a to write a freestanding function like
fn reverse(&mut str)
or uses.chars().rev().collect()
, which requires an allocation.Motivating examples or use cases
I haven't remembered a real-world example; it's in my list for a while. Why not though? :)
Solution sketch
The design should be the same as
[T]::reverse
. First, reverse all bytes, then reverse every char with respect to UTF-8 standard.What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: