This is a fork of the matches crate with an extra unwrap_match!
macro,
and also better error messages for assert_matches
.
unwrap_match!
macroThe unwrap_match!
macro is a general unwrap, used as such:
rust
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.
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.