Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

tisonkun
Copy link
Contributor

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:

  1. Whether we'd add a String::into_char_indices method also?
  2. See inline comment.

@rustbot
Copy link
Collaborator

rustbot commented Nov 15, 2024

Failed to set assignee to programmerjake: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 15, 2024
None => None,
Some((_, ch)) => {
let offset = iter.offset();
drop(self.bytes.drain(..offset));
Copy link
Contributor Author

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.

match iter.next_back() {
None => None,
Some((idx, ch)) => {
self.bytes.truncate(idx);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use vec::IntoIter as the snippet suggested at rust-lang/libs-team#268 (comment) because for next_back, we'd be dropping elements from the back. It's possible to loop self.bytes_iter.next_back(), but using a Vec seems a net win.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants