mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
04045cc83f
Add assert_matches macro. This adds `assert_matches!(expression, pattern)`. Unlike the other asserts, this one ~~consumes the expression~~ may consume the expression, to be able to match the pattern. (It could add a `&` implicitly, but that's noticable in the pattern, and will make a consuming guard impossible.) See https://github.com/rust-lang/rust/issues/62633#issuecomment-790737853 This re-uses the same `left: .. right: ..` output as the `assert_eq` and `assert_ne` macros, but with the pattern as the right part: assert_eq: ``` assertion failed: `(left == right)` left: `Some("asdf")`, right: `None` ``` assert_matches: ``` assertion failed: `(left matches right)` left: `Ok("asdf")`, right: `Err(_)` ``` cc ```@cuviper``` |
||
---|---|---|
.. | ||
benches | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml |