Introduce the assert_matches! macro family#59260
Introduce the assert_matches! macro family#59260Kerollmops wants to merge 2 commits intorust-lang:masterfrom Kerollmops:assert-matches-macros
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::identityfunction: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 theifguard and the other without it.You can test it in the playground.