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 RFC 2500, "Needle API (née Pattern API)" #56345

Closed
12 tasks
Centril opened this issue Nov 29, 2018 · 7 comments
Closed
12 tasks

Tracking issue for RFC 2500, "Needle API (née Pattern API)" #56345

Centril opened this issue Nov 29, 2018 · 7 comments
Assignees
Labels
A-slice Area: [T] A-str Area: str and String C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. 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

@Centril
Copy link
Contributor

Centril commented Nov 29, 2018

This is a tracking issue for the RFC "Needle API (née Pattern API)" (rust-lang/rfcs#2500).

Feature gates:

  • #![feature(needle)] (the traits and method in core::needle itself, and impl of these traits)
  • #![feature(str_find_range)] (find_range, rfind_range, match_ranges and rmatch_ranges methods for str)
  • #![feature(mut_str_needle_methods)] (split_mut, matches_mut, trim_mut etc for str)
  • #![feature(slice_needle_methods)] (find, matches, trim_matches, replace, split etc for [T])
  • #![feature(os_str_needle_methods)] (find, matches etc for OsStr)

Steps:

Unresolved questions:

@Centril Centril added B-RFC-approved Feature: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Nov 29, 2018
@kennytm
Copy link
Member

kennytm commented Nov 29, 2018

(Added a mention to RFC 1672 as promised)

@Centril Centril added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Dec 2, 2018
@Avi-D-coder
Copy link
Contributor

Will std::str::lines be implemented with using this API?
2500-needle.md#standard-library-changes does not explicitly state this.
I believe it would be a mostly backwards compatible change.

@SimonSapin
Copy link
Contributor

Does it matter? This method only takes &self, and returns a dedicated type. Implementation detail changes that are black-box-invisible do not require RFCs. Or, by “mostly” do you mean you expect this change would be observable?

@Avi-D-coder
Copy link
Contributor

Changing the internal implementation does appear to be API compatible.
What I was intending to ask, but didn't, is if it would make sense to treat std::str::lines like the other str methods being deprecated and replaced by Needle API alternatives?

@SimonSapin
Copy link
Contributor

str::lines is already implemented as self.split_terminator('\n').map(LinesAnyMap), with LinesAnyMap stripping one trailing \r if any. (So equivalent to split_terminator with a "\r\n or \n" pattern.)

I think this is subtle enough to be worth a dedicated API. Even if it was as simple as split('\n'), I think this is a common enough use case.

@kennytm kennytm self-assigned this Jan 6, 2019
bors added a commit that referenced this issue Apr 6, 2019
[WIP] Implement Needle API (RFC 2500)

cc #56345

----

Insta-stable changes:

* `impl Index<Range***> for OsStr` cannot be gated and is insta-stable.

I'll add more comments after the crater run.
bors added a commit that referenced this issue Apr 6, 2019
[WIP] Implement Needle API (RFC 2500)

cc #56345

----

Insta-stable changes:

* `impl Index<Range***> for OsStr` cannot be gated and is insta-stable.

I'll add more comments after the crater run.
bors added a commit that referenced this issue Apr 20, 2019
[WIP] Implement Needle API (RFC 2500)

cc #56345

----

Insta-stable changes:

* `impl Index<Range***> for OsStr` cannot be gated and is insta-stable.

I'll add more comments after the crater run.
@pickfire
Copy link
Contributor

Any news on slice::find?

Centril added a commit to Centril/rust that referenced this issue Mar 31, 2020
…=kennytm

Optimize strip_prefix and strip_suffix with str patterns

As mentioned in rust-lang#67302 (comment).
I'm not sure whether adding these methods to `Pattern` is desirable—but they have default implementations so the change is backwards compatible. Plus it seems like they're slated for wholesale replacement soon anyway? rust-lang#56345

----

Constructing a Searcher in strip_prefix and strip_suffix is
unnecessarily slow when the pattern is a fixed-length string. Add
strip_prefix and strip_suffix methods to the Pattern trait, and add
optimized implementations of these methods in the str implementation.
The old implementation is retained as the default for these methods.
Centril added a commit to Centril/rust that referenced this issue Mar 31, 2020
…=kennytm

Optimize strip_prefix and strip_suffix with str patterns

As mentioned in rust-lang#67302 (comment).
I'm not sure whether adding these methods to `Pattern` is desirable—but they have default implementations so the change is backwards compatible. Plus it seems like they're slated for wholesale replacement soon anyway? rust-lang#56345

----

Constructing a Searcher in strip_prefix and strip_suffix is
unnecessarily slow when the pattern is a fixed-length string. Add
strip_prefix and strip_suffix methods to the Pattern trait, and add
optimized implementations of these methods in the str implementation.
The old implementation is retained as the default for these methods.
Centril added a commit to Centril/rust that referenced this issue Mar 31, 2020
…=kennytm

Optimize strip_prefix and strip_suffix with str patterns

As mentioned in rust-lang#67302 (comment).
I'm not sure whether adding these methods to `Pattern` is desirable—but they have default implementations so the change is backwards compatible. Plus it seems like they're slated for wholesale replacement soon anyway? rust-lang#56345

----

Constructing a Searcher in strip_prefix and strip_suffix is
unnecessarily slow when the pattern is a fixed-length string. Add
strip_prefix and strip_suffix methods to the Pattern trait, and add
optimized implementations of these methods in the str implementation.
The old implementation is retained as the default for these methods.
@KodrAus KodrAus added A-str Area: str and String A-slice Area: [T] labels Jul 29, 2020
@KodrAus KodrAus added the Libs-Tracked Libs issues that are tracked on the team's project board. label Jul 29, 2020
@crlf0710 crlf0710 removed the B-RFC-approved Feature: Approved by a merged RFC but not yet implemented. label Jul 26, 2021
@crlf0710
Copy link
Member

According to #76901 (comment) and corresponding t-libs fcp, this rfc is withdrawn. Closing.

cc rust-lang/rfcs#3154

mina86 added a commit to mina86/rust that referenced this issue Feb 16, 2023
Implement Haystack<&[T]> and corresponding Pattern<&[T]> for &[T].
That is, provide implementation for searching for subslices in slices.
This replaces SlicePattern type.

To make use of this new implementations, provide a few new methods on
[T] type modelling them after types on str.  Specifically, introduce
{starts,ends}_with_pattern, find, rfind, [T]::{split,rsplit}_once and
trim{,_start,_end}_matches.

Note that due to existing starts_with and ends_with methods, the
_pattern suffix had to be used.  This is unfortunate but the type
of starts_with’s argument cannot be changed without affecting type
inference and thus breaking the API.

This change doesn’t implement functions returning iterators such as
split_pattern or matches which in str type are built on top of the
Pattern API.

Issue: rust-lang#49802
Issue: rust-lang#56345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-slice Area: [T] A-str Area: str and String C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. 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

7 participants