-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking Issue for string_replace_in_place #147949
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Feature gate:
#![feature(string_replace_in_place)]This is a tracking issue for
String::replace_firstandString::replace_lastPublic API
Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)String::replace_firstandString::replace_lastlibs-team#506String::replace_firstandString::replace_last#134316Unresolved Questions
(copied from ACP "Alternatives" section)
The method names could include
in_placeor similar, to distinguish them fromreplace/replacenmethods onstrthat are not in-place. There is alreadyString::replace_rangethough, that is in-place but does not explicitly indicate this in its name.@tgross35 mentioned on the implementation PR that it would make sense for there to also be an in-place
str::replacealternative. If these are namedreplace_first_in_place, that would match nicely with a possibleString::replace_in_placeand/orString::replacen_in_placethat do whatstr::replace/str::replacendo, but in-place.Users could use the more general
str::replacenif allocation is not a bottleneck, or if the needle and replacement are not the same length and copying the haystack to a new allocation is faster than shuffling data around in one allocation.Users could implement these manually in terms of existing
String/strAPIs (the implementation uses only the existing safe, stable APIsstr::(r)match_indicesandString::replace_range).These could be
fn(self) -> Selfinstead offn(&mut self). This would make it difficult to perform on a mutably borrowedString:*string = std::mem::take(string).replace_first(...);vsstring.replace_first(...);These could be
fn(&mut self) -> &mut Selfto allow chaining multiple calls, but this might be less clear that it does not return a newStringallocation.Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩