-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 some of [T]
’s methods to strings and vice versa
#1152
Add some of [T]
’s methods to strings and vice versa
#1152
Conversation
Is the reason for adding |
@Kimundi I’ve wanted to use it in the past, but yeah, it’s mainly just to match the |
Is there really a usecase for str::chunks or windows? |
Out of curiosity, what is |
@gkoz In principle it's just a runtime-constructed |
@gankro |
Hm, I suspect |
Add the following methods to `str`, presumably as inherent methods: | ||
|
||
- `chunks(&self, n: usize) -> Chunks`: Returns an iterator that yields the | ||
*characters* (not bytes) of the string in groups of `n` at a time. Iterator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“Character” is kinda ambiguous. (Unicode has four different definitions.) Maybe use char
s instead?
+1 to functions involving -1 to |
I just stumbled upon the lack of |
May be out of scope, but I'd like to see some form of |
I concur with @huonw on the dubiousness of windows and chunks in the face of combining characters. It's not clear to me how the Sørensen–Dice coefficient is even supposed to interact with utf8 in that regard. 👍 on the Box conversions. Makes sense. I'm completely indifferent on subslice_offset |
This RFC is now entering its final comment period. |
|
||
- `subslice_offset(&self, inner: &[T]) -> usize`: Returns the offset (in | ||
elements) of an inner slice relative to an outer slice. Panics of `inner` is | ||
not contained within `self`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally prefer to not add this method to slices just yet, I suspect it won't survive stabilization of strings.
I also agree with @huonw about being hesitant to add windows/chunks to strings due to unicode fun stuff. |
- `windows(&self, n: usize) -> Windows`: Returns an iterator over all contiguous | ||
windows of character length `n`. Iterator element type: `&str`. | ||
|
||
- `into_string(self: Box<str>) -> String`: Returns `self` as a `String`. This is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The |
@P1start the libs team seems pretty unanimous about |
@gankro Yep, that’s fine by me. I’ll update the RFC soon to include just those methods (and rename |
RFC updated, removing |
The consensus of the libs team is to merge this RFC, so I will do so. Thanks again @P1start! |
This is the name that was decided in rust-lang/rfcs#1152, and it's better if we say “boxed str” for `Box<str>`. The old name `String::into_boxed_slice` is deprecated.
Rename String::into_boxed_slice -> into_boxed_str This is the name that was decided in rust-lang/rfcs#1152, and it's better if we say “boxed str” for `Box<str>`. The old name `String::into_boxed_slice` is deprecated.
Rename String::into_boxed_slice -> into_boxed_str This is the name that was decided in rust-lang/rfcs#1152, and it's better if we say “boxed str” for `Box<str>`. The old name `String::into_boxed_slice` is deprecated.
Add some methods that already exist on slices to strings and vice versa. Specifically, the following methods should be added:
str::chunks
str::windows
str::into_string
String::into_boxed_slice
<[T]>::subslice_offset
Rendered