-
Notifications
You must be signed in to change notification settings - Fork 9
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
Recommendation for pattern matching #22
Comments
Deref it and match against string |
I would expect a string match to be slower than a TinyStr (primitive int) match. I haven't done benchmarks. |
oh, good point. Might be worth making a macro for matching then |
I think the compiler has the option to do additional optimization when matches are used, so I don't know if PartialEq tells the whole story. I made a new benchmark to specifically test match statement behavior: #23 I have functions with a 15-leaf match, some with str and some with tinystr. Results for me on my Lenovo X1 Carbon:
So, matching on TinyStr is faster, but not greatly so, especially on TinyStr16. |
The solution for pattern matching is to just make a bunch of |
I wonder if if so it's possible |
The problem I previously had with that was const functions don't have a great answer for indexing into variable length strings. We could perhaps have a const function that takes |
Ah, this is still not allowed. I think a custom match macro is probably your best bet There is the vesta crate, a new crate that makes it possible to do generic matches. It may be useful, unsure, but really we can just write our own macro. |
On Rust Nightly, I got the following pattern match to work:
This is fine, but it would be nicer if I could write
Unfortunately, this doesn't seem to work right now.
Is the first example the best way to do pattern matching on TinyStr, or is there a better way?
The text was updated successfully, but these errors were encountered: