rust-lang / rust-lang/rfcs

String methods for replacing a sub-string with another one in place

Open
#2,462 11 comments 17 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

I've often needed to replace a sub-string within a String in place with a new sub-string. If the new sub-string is smaller than the sub-string its replacing, that can be done in place without any allocations.

I don't know if this is the right place to fill in a "feature request", but there is only one correct efficient way to implement such a method, and an RFC feels overkill for that.

The only thing I don't know is how to name it. We could name it String::replace_in_place and String::replacen_in_place but... if the new string is larger than the one it is replacing then an allocation will happen, so "in place" isn't 100% accurate, unless we consider "in place" to mean that it happens on this String, independently of whether it is reallocated or not.

Contributor guide

No contributing guide indexed for this repository

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

Start with the Rust String API and the proposed replace and replacen behavior. Resolve the method naming and allocation semantics, including replacements larger than the matched substring, then document the agreed API and rationale through the RFC process.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
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.