Skip to content

Tracking Issue for {str, [T], Path}::trim_prefix and {str, [T]}::trim_suffix #142312

Closed

Description

@deven

View all comments

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.)

Unresolved Questions

  • None yet.

Footnotes

  1. https://github.com/rust-lang/libs-team/issues/597 ↩

  2. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jun 10, 2025
  2. deven commented on Jun 10, 2025

    @deven
    ContributorAuthor

    @Amanieu, I just noticed that strip_prefix and strip_suffix both exist in slice as well as str. Should I also implement slice::trim_prefix and slice::trim_suffix for consistency? (I could reopen the ACP or open a new one if that makes more sense.)

  3. Amanieu commented on Jun 10, 2025

    @Amanieu
    Member

    Yes, please implement these for slice as well. There is no need for another ACP.

  4. changed the title [-]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`[/+] on Jun 11, 2025
  5. deven commented on Jun 11, 2025

    @deven
    ContributorAuthor

    I submitted the pull request, but it appears I don't have the permissions to update the "S-tracking-unimplemented" label.

  6. added
    S-tracking-ready-to-stabilizeStatus: This is ready to stabilize; it may need a stabilization report and a PR
    and removed on Jun 19, 2025
  7. added a commit that references this issue on Jun 19, 2025
  8. added a commit that references this issue on Jun 19, 2025
  9. added a commit that references this issue on Jun 20, 2025
  10. added a commit that references this issue on Jun 21, 2025
  11. deven commented on Jun 21, 2025

    @deven
    ContributorAuthor

    The pull request (#142331) has been merged to master.

  12. 49 remaining items

  13. removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Jul 8, 2026
  14. rust-rfcbot commented on Jul 8, 2026

    @rust-rfcbot
    Collaborator

    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.

  15. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  16. added 3 commits that reference this issue on Sep 17, 2026
    27918cb
    786aaa7
    03685c2
  17. added 2 commits that reference this issue on Sep 17, 2026
    65b57c3
    ce606c6
  18. added a commit that references this issue on Sep 17, 2026
    873883a
  19. deven commented on Oct 5, 2026

    @deven
    ContributorAuthor

    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?

  20. zachs18 commented on Oct 6, 2026

    @zachs18
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: 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 PRT-libsRelevant 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.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions