-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Impl String::into_chars #133057
base: master
Are you sure you want to change the base?
Impl String::into_chars #133057
Conversation
Failed to set assignee to
|
library/alloc/src/string.rs
Outdated
None => None, | ||
Some((_, ch)) => { | ||
let offset = iter.offset(); | ||
drop(self.bytes.drain(..offset)); |
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.
This reminds me of this thread that suggests a truncate_front
method on Vec
. Not sure if it's desired as a separate proposal.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks for your review! It seems this direction is good to go. I'd create a tracking issue, update the attr in code and add docs with doctests, then request a review for merging. Hopefully in this week. |
This PR is ready for merge from my perspective. Ping @programmerjake @kennytm @Amanieu if you have time to give it a review :D I'd still wonder whether we'd add a String::into_char_indices method also? Seems intuitive and for symmetry. |
This comment has been minimized.
This comment has been minimized.
Looks good, aside from some small nits:
|
@thaliaarchi Thank you! Comments addressed. |
This comment has been minimized.
This comment has been minimized.
@Amanieu Thanks for your review! Comments addressed. |
@Amanieu shall I squash commits by myself? Or the automation could do squash and merge. |
bors squash does not quite work (and was removed iirc), usually you need to do squash by yourself. |
Would |
@slanterns manually squashed. cc @Amanieu
@thaliaarchi we currently store |
if you were to add a impl IntoChars {
pub fn into_string(self) -> String {
// Safety: `bytes` are kept in UTF-8 form, only removing whole `char`s at a time.
unsafe { String::from_utf8_unchecked(self.bytes.collect()) }
}
} |
There could also be a |
This actually collect the rest chars into a new string, instead of transmute. I may leave it to the other PR for the tracking issue and wait a bit for other feedback if it's necessary. Somehow you can already call: let mut it = string.into_chars();
// ..
let new_string = it.collect::<String>(); |
I found But I found this PR gets pending for quite a bit time so I'm hesitate to add new nice to have which cause extra review cycle, unless there is a signal it's to be converged. If the review cycle is timely, making several PRs should be workable also. |
I still hope that the squash process can be automated, or otherwise it's not easy to check the diff and even the author need the history for context. |
This comment has been minimized.
This comment has been minimized.
iirc squashing is not a requirement, so if you feel you're losing important commit history, just don't squash |
@programmerjake Thanks for your information! I was told to do this sometime and not sure if there is a consensus or reference. |
you don't need to feel like I'm telling you what you must do or anything, I'm not one of the people who can approve PRs for this repo anyway so my reviews are merely advisory (I only have that privilege for the portable-simd repos). That said, PRs can normally take more than a month and also this is holiday season (so people may be on vacation and those that aren't may have reduced capacity) and is right before the 2024 edition comes out so taking longer than usual is expected. |
This comment has been minimized.
This comment has been minimized.
I've seen a number of PRs that were merged with multiple commits (e.g. just looking through |
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: tison <wander4096@gmail.com>
Tracking issue - #133125
r? @programmerjake @kennytm @Amanieu
This refers to rust-lang/libs-team#268
Before adding tests and creating a tracking issue, I'd like to reach a consensus on the implementation direction and two questions:
String::into_char_indices
method also?