-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Enhanced Patterns #2899
Comments
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'][..]) |
@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 You'd better use |
@kennytm Exactly and that's why I created this issue so that this will be implemented at some point. |
You'll need to explain
|
|
Should we add that to standard library documentation? And also mention the use of |
As long as this is not yet implemented in std this would be very advantageous. |
All implementors of |
@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:
The text was updated successfully, but these errors were encountered: