Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for string patterns #27721
Comments
alexcrichton
added
T-libs
B-unstable
labels
Aug 12, 2015
This comment has been minimized.
This comment has been minimized.
|
String Patterns RFC tracking issue: #22477 Stabilization not only impacts implementing the pattern traits, but also of course detailed use of the Searcher trait, |
This comment has been minimized.
This comment has been minimized.
|
I'm having trouble seeing the purpose of the |
This comment has been minimized.
This comment has been minimized.
|
@jneem the StrSearcher uses the same code for |
This comment has been minimized.
This comment has been minimized.
|
@bluss I think that helps make my point: AFAICT, all the users of Searcher only call |
This comment has been minimized.
This comment has been minimized.
|
Oops, I missed one: Pattern uses |
This comment has been minimized.
This comment has been minimized.
|
This is useful, I'd like to use it on stable. |
This comment has been minimized.
This comment has been minimized.
|
cc @BurntSushi, Regex is the major pattern user and it would be great for everyone if it was stable because of that. |
This comment has been minimized.
This comment has been minimized.
|
@BurntSushi Are the Pattern traits sufficient for Regex? Any design issues? |
This comment has been minimized.
This comment has been minimized.
|
I wrote the impl for One thing that I don't think is representable with the |
This comment has been minimized.
This comment has been minimized.
|
Nominating for discussion. Not sure whether this is ready for stabilization, but I'd like for the team to dig into it a bit. |
aturon
added
the
I-nominated
label
Jan 27, 2016
This comment has been minimized.
This comment has been minimized.
|
Unfortunately the libs team didn't get a chance to talk about this in terms of stabilization for 1.8, but I'm going to leave the nominated tag as I think we should chat about this regardless. |
This comment has been minimized.
This comment has been minimized.
|
Today I investigated a bit what would need to be done to generalize the Pattern API to arbitrary slice types. As part of that I also took a more pragmatic route to the involved types and interfaces based on these assumptions:
A very rough sketch of the result can be seen below. Note that this is only the Pattern traits itself, without actual integration in the std lib or comprehensive re implementation of the existing types. https://github.com/Kimundi/pattern_api_sketch/blob/master/src/v5.rs The core changes are:
Changes in regard to the open questions:
|
alexcrichton
referenced this issue
Feb 18, 2016
Closed
Tracking issue for Add a generic string pattern matching API (RFC 528) #22477
This comment has been minimized.
This comment has been minimized.
|
Is the focus of Pattern for slices going to be specific for |
This comment has been minimized.
This comment has been minimized.
|
@bluss: I only used The |
This comment has been minimized.
This comment has been minimized.
|
I'm currently trying out some runtime scanners for let_scan!("before:after", (let word_0 <| until(":"), ":", let word_1: Everything));
assert_eq!(word_0, "before");
assert_eq!(word_1, "after");The problem I'm having is that it's really painful to actually do this. The interface as it exists seems to assume that ownership of the pattern can be passed to the method which will use it, and as a result, can only be used exactly once. This doesn't make much sense to me. Searching for a pattern should not (in general) consume the pattern. What I want is The more I think about this, the more it comes down to the I can work around this by requiring |
This comment has been minimized.
This comment has been minimized.
|
Oh, another thing I just realised: there doesn't appear to be any way to find out how long a match is given a pattern and, say, |
This comment has been minimized.
This comment has been minimized.
|
You can use .next_reject for that. |
This comment has been minimized.
This comment has been minimized.
|
Hey, I don't know a lot about this API, but I noticed that
|
This comment has been minimized.
This comment has been minimized.
|
@withoutboats A slice of chars represents a set of possibilities, so it's not like a string; either of the chars can be matched by themselves. |
This comment has been minimized.
This comment has been minimized.
|
@bluss That makes sense. The semantics of |
aturon
removed
the
I-nominated
label
Jun 9, 2016
This comment has been minimized.
This comment has been minimized.
|
Can we say that, after returning |
bors
added a commit
that referenced
this issue
Aug 23, 2016
cuviper
pushed a commit
to cuviper/rayon
that referenced
this issue
Mar 28, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm a big fan of extending this to be more generic than just str, needed/wanted it for [u8] quite frequently. Unfortunately, there's an API inconsistency already - str::split takes a Pattern, whereas slice::split takes a predicate function that only looks at a single T in isolation. |
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
@shahn That shouldn't be a big problem - if |
This comment has been minimized.
This comment has been minimized.
Lisoph
commented
Jan 11, 2018
|
I strongly agree with widening the API to slice and maybe Vec. |
This comment has been minimized.
This comment has been minimized.
|
What's the status here? The original RFC is quite old -- from 2014, before 1.0 -- do we need to completely revisit the design? What are the current blockers? |
This comment has been minimized.
This comment has been minimized.
|
With SIMD stabilizing in 1.27, Jetscii will be available on stable, but its |
This comment has been minimized.
This comment has been minimized.
jeekobu
commented
May 14, 2018
|
Would be nice to see these for OsStr, CStr, [u8] and similar, as mentioned a year ago. Non-UTF in Rust feels very much a second class citizen and this would be a start. |
This comment has been minimized.
This comment has been minimized.
scottmcm
referenced this issue
Oct 26, 2018
Open
Add `.count_starts_with` and `.count_ends_with` to String #55326
This comment has been minimized.
This comment has been minimized.
Mingun
commented
Mar 24, 2019
|
I think, that |
alexcrichton commentedAug 12, 2015
•
edited by bstrie
(Link to original RFC: rust-lang/rfcs#528)
This is a tracking issue for the unstable
patternfeature in the standard library. We have many APIs which support the ability to search with any number of patterns generically within a string (e.g. substrings, characters, closures, etc), but implementing your own pattern (e.g. a regex) is not stable. It would be nice if these implementations could indeed be stable!Some open questions are:
cc @Kimundi