-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add len method to std::string::String
#7526
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
base: master
Are you sure you want to change the base?
Conversation
|
👍 |
|
Keeping this PR in draft before we decide if we want the
I would argue here against returning number of characters and returning number of bytes, as Rust is doing it. Here are my reasons for that approach:
@bitzoic @xunilrj Having your views here would be highly appreciated. |
|
Using |
@bitzoic I am a bit confused here. As discussed in the comment above as well in the PR description, Returning code points or graphemes would diverge from Rust and IMO cause other issues listed in the comment above.
The semantics of a My overall reasoning is that we primarily borrow from Rust, both in the language and I am fine with having |
|
I am for Returning number of chars/graphemes is |
Interesting I thought |
PR SummaryIntroduces a byte-length accessor for
Written by Cursor Bugbot for commit 6a55bb8. This will update automatically on new commits. Configure here. |
Description
This PR adds
lenmethod tostd::string::Stringby exposing the length of the underlyingBytes.Currently, the least expensive way to obtain a
String's length is to callsome_string.as_str().len()which is a considerable performance overhead for a very common operation of getting the length. It is also a regular part of string APIs and as such expected.This assumes that we want to have the same semantics as the Rust's
std::string::Stringwherelenreturns the number of bytes and not characters or graphems: https://doc.rust-lang.org/std/string/struct.String.html#method.lenChecklist
Breaking*orNew Featurelabels where relevant.