Repository navigation
Enhanced Patterns #2899
Description
Activity
I suspect this falls under rust-lang/rust#56345 / RFC #2500 "Needle API" somehow, though I've never fully understood that RFC
You don't even need #2500 for this.
s.contains(&['a', 'b'][..])
Reacted by Jake Goulding, Ivan Tham, Kevin Stenerson, Iago-lito, HansvdLaan and Rahul Butani@kennytm Yes, that's right, but that's not the only thing.
s.contains(&["abcd", "aaaa"]);
does also not work because that Pattern is only implemented in char-slices. An &str will be compared char by char. But what if we analyze that pattern in compile-time and see that the strings start with the same chars in this case "a". Why do we need to check these chars twice? Do you understand?
@deeprobin The standard library is not capable of "analyzing that pattern to see that strings both start with
a" in run-time, let alone in compile-time.You'd better use
aho-corasickif you need to efficiently search for"abcd" || "aaaa".Reacted by Jake Goulding, Iago-lito and Rahul Butani@kennytm Exactly and that's why I created this issue so that this will be implemented at some point.
You'll need to explain
- why we need to essentially move
aho-corasickinto std to support searching multiple strings efficiently — is this feature so essential that crates.io is insufficient, and must be provided by the standard library? (and at this point why not just moveregexinto std) - is that
a || bsyntax needed
Reacted by Jake Goulding, Iago-lito and Rachel Knight- why we need to essentially move
-
I think one should optimize what can be optimized. That means you should at least support simple multi-patterns like
aho-corasick.regexsupports more complicated patterns where I can maybe understand something that is not in the std. -
The
a || bsyntax is of course not absolutely necessary but would make the code a bit clearer.
-
s.contains(&['a', 'b'][..])
Should we add that to standard library documentation? And also mention the use of
aho-corasickorregexif they need additional stuff.Reacted by Iago-litos.contains(&['a', 'b'][..])
Should we add that to standard library documentation? And also mention the use of
aho-corasickorregexif they need additional stuff.As long as this is not yet implemented in std this would be very advantageous.
Should we add that to standard library documentation
All implementors of
Patternare automatically documented@shepmaster Yes, but there are no examples there. Also the description is inconsistent, some ends with a period but some doesn't.
std::pattern::Pattern could be "hello".
Example:
But it is also faster to do multi checks instead of using multiple contains functions.
Bad practise
I created myself a Pattern implementation which is about 19ns and does just one check. But I think there must be a own pattern syntax.
Something like: