Repository navigation
Tracking Issue for slice_strip feature #73413
Copy link
Copy link
Closed
Labels
A-sliceArea: `[T]`Area: `[T]`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.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 RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Description
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
- Implement the feature (cc @rust-lang/libs)
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved Questions
None
Implementation history
- Implemented in Implement
slice_stripfeature #73414 - Assembly for
[u8]: https://rust.godbolt.org/z/iMcqf-
Metadata
Metadata
Assignees
Labels
A-sliceArea: `[T]`Area: `[T]`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.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 RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Activity
Rollup merge of rust-lang#73414 - lzutao:slice_strip, r=dtolnay
Rollup merge of rust-lang#73414 - lzutao:slice_strip, r=dtolnay
Rollup merge of rust-lang#73414 - lzutao:slice_strip, r=dtolnay
Rollup merge of rust-lang#73414 - lzutao:slice_strip, r=dtolnay
ijackson commentedon 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 commentedon 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 commentedon Sep 13, 2020
I'm also interested! I want to use this to trim null bytes from the end of a slice.
tesuji commentedon 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 tointroduce a new method for that functionality.
Rua commentedon 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 commentedon 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 commentedon Sep 13, 2020
tesuji commentedon Sep 13, 2020
Ah yeah, I forgot about this, thanks for pointing it out.
I'm not really sure, T-libs member should have more experience to answer this question.
My English is not great, so I pinged Joshua for review your PR.
You could always send a PR for stabilization, documentation improvements is not a blocker for stabilizing it.
ijackson commentedon Sep 13, 2020
docs: Reword `slice::strip_prefix` and `strip_suffix` a bit
Rollup merge of rust-lang#77853 - ijackson:slice-strip-stab, r=Amanieu
Auto merge of rust-lang#77853 - ijackson:slice-strip-stab, r=Amanieu
ijackson commentedon 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 commentedon Jan 8, 2021
Closed by #77853 .