| Crates.io | matches2 |
| lib.rs | matches2 |
| version | 1.2.1 |
| created_at | 2018-06-10 13:32:13.854136+00 |
| updated_at | 2019-11-24 05:34:41.061761+00 |
| description | A macro to evaluate, as a boolean, whether an expression matches a pattern. |
| homepage | |
| repository | https://github.com/Laaas/matches2 |
| max_upload_size | |
| id | 69461 |
| size | 11,094 |
This is a fork of the matches crate with an extra unwrap_match! and option_match! macro,
and also better error messages for assert_matches.
unwrap_match! macroThe unwrap_match! macro is a general unwrap, used as such:
let output = unwrap_match!(input, AnEnum::Variant(a) | AnEnum::OtherVariant(a) if a < 5 * 2 => a);
If it fails, it emits a descriptive error including the pattern and the input,
for this reason input must implement Debug, unless you provide a custom error message
as the last arguments, in the same way you'd use format!.
option_match! macroThe option_match! macro is like unwrap_match!, except instead of failing,
it just returns an Option.
let output: Option<_> = option_match!(input, AnEnum::Variant(a) | AnEnum::OtherVariant(a) if a < 5 * 2 => a);
The original matches crate would emit horrible errors when assertions failed,
outputting a pattern such as Some(_) as Some ( _ ). This version has properly
formatted errors, so you will never experience this again.