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

Add String::replace_first and String::replace_last #134316

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zachs18
Copy link
Contributor

@zachs18 zachs18 commented Dec 14, 2024

Rebase of #97977 (cc @WilliamVenner)

Convenience methods that use match_indices and replace_range to efficiently replace a substring in a string without reallocating, if capacity (and the implementation of Vec::splice) allows.

The intra-doc link to str::replacen is a direct url-based link to str::replacen in std's docs to work around #98941. This means that when building only alloc's docs (and not std's), it will be a broken link. There is precedent for this e.g. in core::hint::spin_loop which links to std::thread::yield_now using a url-based link and thus is a dead link when only building core's docs.

WilliamVenner and others added 3 commits December 14, 2024 13:52
@rustbot
Copy link
Collaborator

rustbot commented Dec 14, 2024

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Dec 14, 2024
@tgross35
Copy link
Contributor

I don't think I see any libs-api feedback on the other thread, and that is from a while back anyway. Could you file an ACP for this at https://github.com/rust-lang/libs-team/issues?

@tgross35
Copy link
Contributor

These methods would be convenient but I feel like they should probably come with an in-place replace alternative.

@rust-log-analyzer

This comment has been minimized.

@zachs18
Copy link
Contributor Author

zachs18 commented Dec 15, 2024

ACP opened: rust-lang/libs-team#506

@rustbot label S-waiting-on-ACP

I added String::replace_in_place (doing str::replace in-place) as a possible alternative/addition in the ACP, but I'll hold off on adding it if/until the ACP is approved with it.

@rustbot rustbot added the S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. 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.

5 participants