Repository navigation
Tracking Issue for {str, [T], Path}::trim_prefix and {str, [T]}::trim_suffix #142312
Copy link
Copy link
Closed
Closed
Copy link
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-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
Feature gate: #![feature(trim_prefix_suffix)]
This is a tracking issue for adding trim_prefix and trim_suffix methods to str that remove at most one occurrence of a specified prefix or suffix while always returning a string slice (rather than Option<&str>), enabling easy method chaining.1
Public API
impl str {
pub fn trim_prefix<P>(&self, prefix: P) -> &str
where
P: Pattern;
pub fn trim_suffix<P>(&self, suffix: P) -> &str
where
P: Pattern,
for<'a> P::Searcher<'a>: ReverseSearcher<'a>;
}
impl [T] {
pub fn trim_prefix<P>(&self, prefix: &P) -> &[T]
where
P: SlicePattern<Item = T> + ?Sized,
T: PartialEq;
pub fn trim_suffix<P>(&self, suffix: &P) -> &[T]
where
P: SlicePattern<Item = T> + ?Sized,
T: PartialEq;
}
impl Path {
pub fn trim_prefix<P>(&self, base: P) -> &Path
where
P: AsRef<Path>;
}Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
- Implementation: Add
trim_prefixandtrim_suffixmethods for bothsliceandstrtypes. #142331 - Final comment period (FCP)2
- Stabilization PR
Unresolved Questions
- None yet.
Footnotes
Reactions are currently unavailable
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-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PRStatus: This is ready to stabilize; it may need a stabilization report and a PRT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
deven commentedon Jun 10, 2025
@Amanieu, I just noticed that
strip_prefixandstrip_suffixboth exist insliceas well asstr. Should I also implementslice::trim_prefixandslice::trim_suffixfor consistency? (I could reopen the ACP or open a new one if that makes more sense.)Amanieu commentedon Jun 10, 2025
Yes, please implement these for
sliceas well. There is no need for another ACP.[-]Tracking Issue for `str::trim_prefix` and `str::trim_suffix`[/-][+]Tracking Issue for `str::trim_prefix`, `str::trim_suffix`, `slice::trim_prefix` and `slice::trim_suffix`[/+]Add trim_prefix and trim_suffix for slice and str.
deven commentedon Jun 11, 2025
I submitted the pull request, but it appears I don't have the permissions to update the "S-tracking-unimplemented" label.
Rollup merge of rust-lang#142331 - deven:trim_prefix_suffix, r=Amanieu
Rollup merge of rust-lang#142331 - deven:trim_prefix_suffix, r=Amanieu
Rollup merge of rust-lang#142331 - deven:trim_prefix_suffix, r=Amanieu
Unrolled build for #142331
deven commentedon Jun 21, 2025
The pull request (#142331) has been merged to master.
49 remaining items
rust-rfcbot commentedon Jul 8, 2026
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
Rollup merge of rust-lang#160544 - zachs18:stabilize-trim_prefix_suff…
Rollup merge of rust-lang#160544 - zachs18:stabilize-trim_prefix_suff…
Rollup merge of rust-lang#160544 - zachs18:stabilize-trim_prefix_suff…
Rollup merge of rust-lang#160544 - zachs18:stabilize-trim_prefix_suff…
Rollup merge of rust-lang#160544 - zachs18:stabilize-trim_prefix_suff…
Unrolled build for #160544 in rollup 162907
deven commentedon Oct 5, 2026
This was closed as completed on September 17, yet Rust 1.99.0 was released on October 1 with this still marked as a nightly-only experimental API. Shouldn't it have been stabilized in 1.99.0?
zachs18 commentedon Oct 6, 2026
No, it will be stable in Rust 1.100.0. Rust has a release model with a "beta" release where newly-stabilized features can be tested (and sometimes adjusted/reverted) before becoming fully stable. See also https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
The PR stabilizing this feature was merged before 1.100.0 beta branched from nightly, so it will be in Rust 1.100.0 stable (barring a revert). It won't be in Rust 1.99.0 stable because the PR was merged after Rust 1.99.0 beta branched from nightly (but before Rust 1.99.0 beta "became" Rust 1.99.0 stable).
If you look at the beta stdlib docs, the functions are listed as stable as of 1.100.0.