#assert #match #pattern

dev assert_matches

Asserts that a value matches a pattern

5 stable releases

1.3.0 Jul 12, 2018
1.2.0 Mar 6, 2018
1.1.0 Feb 4, 2017
1.0.1 Jun 22, 2016
1.0.0 Feb 16, 2016

#63 in Rust patterns

Download history 10622/week @ 2019-12-17 5066/week @ 2019-12-24 7130/week @ 2019-12-31 12467/week @ 2020-01-07 12101/week @ 2020-01-14 12640/week @ 2020-01-21 11585/week @ 2020-01-28 8764/week @ 2020-02-04 5828/week @ 2020-02-11 5990/week @ 2020-02-18 6261/week @ 2020-02-25 7472/week @ 2020-03-03 7554/week @ 2020-03-10 7214/week @ 2020-03-17 7060/week @ 2020-03-24 6555/week @ 2020-03-31

34,852 downloads per month
Used in 191 crates (127 directly)

MIT/Apache

12KB
193 lines

assert_matches

Provides a macro, assert_matches, which tests whether a value matches a given pattern, causing a panic if the match fails.

Documentation

#[macro_use] extern crate assert_matches;

#[derive(Debug)]
enum Foo {
    A(i32),
    B(i32),
}

let a = Foo::A(1);

assert_matches!(a, Foo::A(_));

assert_matches!(a, Foo::A(i) if i > 0);

To include in your project, only when tests are compiled, add the following to your Cargo.toml:

[dev-dependencies]
assert_matches = "1.2"

And add the following to your crate root:

#[cfg(test)] #[macro_use]
extern crate assert_matches;

License

assert_matches is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.


lib.rs:

Provides a macro, assert_matches!, which tests whether a value matches a given pattern, causing a panic if the match fails.

See the macro assert_matches! documentation for more information.

Also provides a debug-only counterpart, debug_assert_matches!.

See the macro debug_assert_matches! documentation for more information about this macro.

No runtime deps