#assert #match #pattern

no-std dev assert_matches

Asserts that a value matches a pattern

7 stable releases

Uses old Rust 2015

1.5.0 Feb 5, 2021
1.4.0 Oct 4, 2020
1.3.0 Jul 12, 2018
1.2.0 Mar 6, 2018
1.0.0 Feb 16, 2016

#4 in No standard library

Download history 169495/week @ 2023-11-07 182696/week @ 2023-11-14 149330/week @ 2023-11-21 184170/week @ 2023-11-28 175194/week @ 2023-12-05 159966/week @ 2023-12-12 124054/week @ 2023-12-19 59103/week @ 2023-12-26 140477/week @ 2024-01-02 139634/week @ 2024-01-09 160304/week @ 2024-01-16 169304/week @ 2024-01-23 171108/week @ 2024-01-30 171709/week @ 2024-02-06 163299/week @ 2024-02-13 143544/week @ 2024-02-20

681,041 downloads per month
Used in 1,224 crates (637 directly)

MIT/Apache

14KB
209 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.5"

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