rust-lang / rust-lang/rust

Tracking Issue for `str::replace_with`

Open
#147,731 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue S-tracking-unimplemented T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(replace_with)]

This is a tracking issue for the implementation of replace_with and replacen_with for the String type in standart library, followed from the ACP (https://github.com/rust-lang/libs-team/issues/344#issuecomment-3404030290).

This feature adds str::replace_with as an augmentation of str::replace and str::replacen_with as an augmentation of str:replacen to the standard library. Compared to the current versions, these functions allow for passing an f: impl FnMut(&str) -> S that can be used to produce replacements dynamically as well as to insert custom computations such as counting the number of changes.

Public API
// str::replace_with

fn replace_with<P: Pattern, S: AsRef<str>>(
    &self,
    from: P,
    f: impl FnMut(&str) -> S,
) -> String;
// str::replacen_with

fn replacen_with<P: Pattern, S: AsRef<str>>(
    &self,
    from: P,
    f: impl FnMut(&str) -> S,
    count: usize
) -> String;
Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions
  • None yet.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the proposed str::replace_with and str::replacen_with signatures, then review the linked implementation PR rust-lang/rust#147741 and the ACP discussion. The remaining tracking steps are the final comment period and a stabilization PR; done means those lifecycle steps have been completed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.