Skip to content

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

Open
@gnzlbg

Description

@gnzlbg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions