Skip to content

Tracking Issue for slice_strip feature #73413

Closed

Description

@tesuji

The feature gate for the issue is #![feature(slice_strip)].

This feature adds two new methods to [T]:

impl<T> [T] {
    /// Returns a subslice with the prefix removed.
    pub fn strip_prefix(&self, prefix: &[T]) -> Option<&[T]> where T: PartialEq;
    /// Returns a subslice with the suffix removed.
    pub fn strip_suffix(&self, suffix: &[T]) -> Option<&[T]> where T: PartialEq;
}

This is an analogy feature like str::strip_{prefix,suffix} but has the same signature of slice's {starts,ends}_with.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

None

Implementation history

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jun 16, 2020
  2. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    T-libs-api[DEPRECATED; DO NOT USE]
    on Jun 16, 2020
  3. added a commit that references this issue on Jun 25, 2020
  4. added 3 commits that reference this issue on Jun 26, 2020
  5. added
    Libs-SmallLibs issues that are considered "small" or self-contained
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Jul 29, 2020
  6. ijackson commented on Aug 3, 2020

    @ijackson
    Contributor

    Hi. I accidentally used one of these functions, I think because I was reading the docs for str :-). So, I conclude that they're useful.

    I'd like to see them stabilised. Since the docs tickbox was unticked I looked at the docs, and I have I made an MR for some slight docs wording improvements: #75078

    I think this is probably ready for stabilisation.

    @lzutao Thanks for your contribution here. Do you intend to do the stabilisation report etc.?

  7. tesuji commented on Aug 3, 2020

    @tesuji
    ContributorAuthor

    I think it is a bit soon to stabilize this feature. It is about one month after the feature is merged and appeared on nightly.
    But yeah, you could send a PR to propose stabilize this feature, but it should include real use cases.

  8. Rua commented on Sep 13, 2020

    @Rua
    Contributor

    I'm also interested! I want to use this to trim null bytes from the end of a slice.

  9. tesuji commented on Sep 13, 2020

    @tesuji
    ContributorAuthor

    Could you give some example code show how do you do that with slice::strip_ methods?
    Because if you are running strip_* in a loop, I think it is kinda not cool, it is might be better to
    introduce a new method for that functionality.

  10. Rua commented on Sep 13, 2020

    @Rua
    Contributor

    You're right, what I'm looking for is a slice equivalent to str::trim_end_matches. Which would also be welcome, but out of scope here!

  11. tesuji commented on Sep 13, 2020

    @tesuji
    ContributorAuthor

    I just don't know if we want the API as it is, because we could bound the prefix/suffix arguments by Pattern API
    like str. @withoutboats and some folks was talking about fixing Pattern API for slices.

    Anyway, If you want to stabilize this API, you could just send a PR and ping T-libs for their decisions.

  12. ijackson commented on Sep 13, 2020

    @ijackson
    Contributor
  13. tesuji commented on Sep 13, 2020

    @tesuji
    ContributorAuthor

    The current unstable strip_* functions match the signatures of the starts_with and ends_with, as discussed in #73414.

    Ah yeah, I forgot about this, thanks for pointing it out.

    Ie, AIUI subsequently introducing such a alice Pattern API would not be a breaking change. If I'm wrong about that then stabilising starts_with and ends_with in their current form seems like it was a mistake ?

    I'm not really sure, T-libs member should have more experience to answer this question.

    Would you be able to look into that ?

    My English is not great, so I pinged Joshua for review your PR.

    The stabilisation checklist says to look at the docs

    You could always send a PR for stabilization, documentation improvements is not a blocker for stabilizing it.

  14. ijackson commented on Sep 13, 2020

    @ijackson
    Contributor
  15. added a commit that references this issue on Jan 7, 2021
  16. added a commit that references this issue on Jan 7, 2021
  17. ijackson commented on Jan 7, 2021

    @ijackson
    Contributor

    I think this issue wants to be set to merged or something now? The docs were dealt with in #75078 and the stabilisation was in #77853, both merged now. I'm not sure I can do that myself...

  18. tesuji commented on Jan 8, 2021

    @tesuji
    ContributorAuthor

    Closed by #77853 .

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

    A-sliceArea: `[T]`B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions