-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Introduce the assert_matches! macro family #59260
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Really cool idea, I like this macro a lot. |
I do not know how to bring this unstable macro into scope, tried with the |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I would strongly prefer not baking a matcher Finally, with #53667 (which I'm working on implementing) you can encode an |
Thanks for the PR @Kerollmops! This is a pretty large-ish feature to libstd, however, so I was wondering if there's an accompanying RFC for it? If not I think this feature would want to go through an RFC before being added to libstd (even unstable) |
☔ The latest upstream changes (presumably #59478) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage @KarolinePlum you need to resolve the conflicts so we can merge this |
ping from triage @KarolinePlum |
Since I'd imagine it'd be just as useful as |
We now have an |
This pull request introduce two new macros, the
assert_matches!
anddebug_assert_matches!
.A new family is born 🎉
These macros can be very helpful when doing tests, more practical than doing a match and a panic by hand. It could be classified into the same category of tools than the
dgb!
macro or thestd::convert::identity
function:If you wanted to know why I did not use the
?
macro operator it is because it seems that the libcore crate is not under 2018 edition therefore this operator is not available. As a workaround I used a macro that can have two different inputs: one with theif
guard and the other without it.You can test it in the playground.