Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for slice_strip feature #73413

Closed
3 tasks done
tesuji opened this issue Jun 16, 2020 · 11 comments
Closed
3 tasks done

Tracking Issue for slice_strip feature #73413

tesuji opened this issue Jun 16, 2020 · 11 comments
Labels
A-slice Area: `[T]` B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Jun 16, 2020

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

@tesuji tesuji added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Jun 16, 2020
@jonas-schievink jonas-schievink added B-unstable Blocker: Implemented in the nightly compiler and unstable. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 16, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 25, 2020
Implement `slice_strip` feature

Tracking issue: rust-lang#73413
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 26, 2020
Implement `slice_strip` feature

Tracking issue: rust-lang#73413
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 26, 2020
Implement `slice_strip` feature

Tracking issue: rust-lang#73413
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 2, 2020
Implement `slice_strip` feature

Tracking issue: rust-lang#73413
@KodrAus KodrAus added A-slice Area: `[T]` Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. labels Jul 29, 2020
@ijackson
Copy link
Contributor

ijackson commented Aug 3, 2020

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

@tesuji
Copy link
Contributor Author

tesuji commented Aug 3, 2020

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.

@Rua
Copy link
Contributor

Rua commented Sep 13, 2020

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

@tesuji
Copy link
Contributor Author

tesuji commented Sep 13, 2020

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.

@Rua
Copy link
Contributor

Rua commented Sep 13, 2020

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!

@tesuji
Copy link
Contributor Author

tesuji commented Sep 13, 2020

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.

@ijackson
Copy link
Contributor

ijackson commented Sep 13, 2020 via email

@tesuji
Copy link
Contributor Author

tesuji commented Sep 13, 2020

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.

@ijackson
Copy link
Contributor

ijackson commented Sep 13, 2020 via email

ijackson added a commit to ijackson/rust that referenced this issue Oct 12, 2020
The stabilisation issue, rust-lang#73413, has an open item for documentation.
I looked at the docs and it is all there, but I felt it could do with
some minor wording improvement.

I looked at the `str::strip_prefix` docs for a template.  (That
resulted in me slightly changing that doc too.)

I de-linkified `None` and `Some`, as I felt that rather noisy..  I
searched stdlib, and these don't seem to be usually linkified.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 7, 2021
Stabilize slice::strip_prefix and slice::strip_suffix

These two methods are useful.  The corresponding methods on `str` are already stable.

I believe that stablising these now would not get in the way of, in the future, extending these to take a richer pattern API a la `str`'s patterns.

Tracking PR: rust-lang#73413.  I also have an outstanding PR to improve the docs for these two functions and the corresponding ones on `str`: rust-lang#75078

I have tried to follow the [instructions in the dev guide](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr).  The part to do with `compiler/rustc_feature` did not seem applicable.  I assume that's because these are just library features, so there is no corresponding machinery in rustc.
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 7, 2021
Stabilize slice::strip_prefix and slice::strip_suffix

These two methods are useful.  The corresponding methods on `str` are already stable.

I believe that stablising these now would not get in the way of, in the future, extending these to take a richer pattern API a la `str`'s patterns.

Tracking PR: rust-lang#73413.  I also have an outstanding PR to improve the docs for these two functions and the corresponding ones on `str`: rust-lang#75078

I have tried to follow the [instructions in the dev guide](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr).  The part to do with `compiler/rustc_feature` did not seem applicable.  I assume that's because these are just library features, so there is no corresponding machinery in rustc.
@ijackson
Copy link
Contributor

ijackson commented Jan 7, 2021

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

@tesuji
Copy link
Contributor Author

tesuji commented Jan 8, 2021

Closed by #77853 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-slice Area: `[T]` B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants