-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Remove string [] indexing #12710
Comments
nominating |
Seconded. In a UTF-8 world, what we think of as a "string" is emphatically not an array. |
+1, it's rarely correct to index strings at all, and especially not by bytes |
I would also be for removing the |
+1 |
I volunteer to work on this. By the way, we do have a function to decode character points right? |
~str in patterns seems to be blocking this. I'll try work on that and come back to this later. |
Why would string pattern matching affect string indexing? |
I'm not sure myself. After removing string indexing, I got "internal On Wed, Mar 5, 2014 at 7:05 PM, Huon Wilson [email protected]:
|
This will probably fall out of the changes we plan for DST, or at |
Accepted for 1.0, P-backcompat-libs. |
@thestinger Removal of |
Any hints what has to change in the code to fix this? I took a peek but got lost in trait lookups, while I thought slice indexing was built-in. |
@brson hmm, I think the PRIMARY thing that has to change is |
the function |
Thanks, @nikomatsakis. I've started a patch. |
Being able to index into the bytes of a string encourages poor UTF-8 hygiene. To get a view of `&[u8]` from either a `String` or `&str` slice, use the `as_bytes()` method. Closes rust-lang#12710. [breaking-change]
Rust strings feel much less intuitive to me than Python's |
Being able to index into the bytes of a string encourages poor UTF-8 hygiene. To get a view of `&[u8]` from either a `String` or `&str` slice, use the `as_bytes()` method. Closes #12710. [breaking-change] If the diffstat is any indication this shouldn't have a huge impact but it will have some. Most changes in the `str` and `path` module. A lot of the existing usages were in tests where ascii is expected. There are a number of other legit uses where the characters are known to be ascii.
It is byte indexing (not character indexing) which is encouraging poor UTF-8 hygiene, and the behaviour can be regained either with the
.bytes()
iterator, or justs.as_bytes()
to get a&[u8]
view (at zero cost).The text was updated successfully, but these errors were encountered: