Skip to content

Impl String::into_chars - #133057

Merged
bors merged 1 commit into
rust-lang:masterfrom
tisonkun:into-chars
Jan 8, 2025
Merged

bors merged 1 commit into
rust-lang:masterfrom
tisonkun:into-chars

Conversation

@tisonkun

@tisonkun tisonkun commented Nov 15, 2024 •

Copy link
Copy Markdown
Contributor

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:

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

@rustbot

rustbot commented Nov 15, 2024

Copy link
Copy Markdown
Collaborator

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
Comment thread library/alloc/src/string.rs Outdated
None => None,
Some((_, ch)) => {
let offset = iter.offset();
drop(self.bytes.drain(..offset));

Copy link
Copy Markdown
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.

Comment thread library/alloc/src/string.rs Resolved
@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.

Comment thread library/alloc/src/string.rs Resolved
Comment thread library/alloc/src/string.rs Resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@tisonkun

ghost commented Nov 15, 2024

Copy link
Copy Markdown
Contributor Author

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.

@tisonkun

ghost commented Nov 17, 2024 •

Copy link
Copy Markdown
Contributor Author

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.

@rust-log-analyzer

This comment has been minimized.

@thaliaarchi

ghost commented Nov 17, 2024 •

Copy link
Copy Markdown
Contributor

Looks good, aside from some small nits:

  • unsafe { self.bytes.advance_by(offset).unwrap_unchecked() } and let _ = self.bytes.advance_back_by(len - idx) should be consistent. I think ignoring with _ is better.
  • Looks like iter and size_hint are missing #[inline].
  • The crate::vec imports can be simplified from two lines to use crate::vec::{self, Vec} to match the other imports.

@tisonkun

ghost commented Nov 17, 2024

Copy link
Copy Markdown
Contributor Author

@thaliaarchi Thank you! Comments addressed.

@rust-log-analyzer

This comment has been minimized.

@programmerjake

ghost commented Dec 22, 2024

Copy link
Copy Markdown
Member

@programmerjake Thanks for your information! I was told to do this sometime and not sure if there is a consensus or reference.

I've seen a number of PRs that were merged with multiple commits (e.g. just looking through git log I found #134601 which was merged with 2 separate commits), so my assumption is that's fine. I might rebase to squash commits that weren't useful to have separate (e.g. 5 commits in a row fixing typos could be 1 commit) but if the commits are useful to have separate, then afaict keep them separate if you prefer.

@rust-log-analyzer

This comment has been minimized.

@programmerjake

This comment was marked as resolved.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun

ghost commented Jan 6, 2025

Copy link
Copy Markdown
Contributor Author

Hello @Amanieu! May we have another review around?

@Amanieu

ghost commented Jan 7, 2025

Copy link
Copy Markdown
Member

Sorry for the delay, I'm currently going through my PR review backlog.

@bors r+

@bors

ghost commented Jan 7, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 7218fd1 has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 7, 2025
@bors
bors merged commit e7ee582 into rust-lang:master Jan 8, 2025
@rustbot rustbot added this to the 1.86.0 milestone Jan 8, 2025
@tisonkun
tisonkun deleted the into-chars branch January 15, 2025 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants