Allow &[&str] in Pattern

At least in rust the char type is 4 bytes always.

There might also be a requirement for it to be a valid Unicode code point but I am a bit hazy on that.

But you can't match a raw char (effectively a value-limited raw u32) against a str (utf-8 bytes). You have to convert somewhere.

Usually the correct tradeoff here would be to encode the (small number of) chars you are searching for and search for those values in the string. Except that then you'd probably really like to build a small state machine compiled from those bytes. Exactly what a regex does.

Sometimes regex isn't what you want though. Sometimes you'd want to index your corpus and search the index. A database index? A full text index? I don't know; there are crates for both.

Searching in text is a complex topic with multiple associated tradeoffs. In these cases the Rust std MO has been not to guess. Libraries and crates exist which make the various tradeoffs clear. The proposed &[&str] pattern implementation, whatever it is intended to mean, probably does not belong in std.

1 Like

Can we deprecate Pattern then?

Ideally, Pattern would be stabilized and used both for the simple cases in the standard library and more complex cases implemented in third-party crates like aho-corasick and regex.

Even if it were not, we wouldn't deprecate something just because it has some imperfections or doesn't work for every single use case. The standard library can co-exist with external libraries like aho-corasick. There's no need to break existing, working code; it doesn't make solving your problems easier. Please remember that the Rust project has committed to not breaking programs that build with the stable compiler and libraries, with very few exceptions.

12 Likes

Moreover it's an accepted RFC.

Then provide an impl and benchmark, rather than asking others to do it. If the impl is both simple and fast, as you claim, you should be able to provide one fairly easily, and at that point there'd be little reason not to use it.

7 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.