#pattern-match #expression #boolean #debugging #evaluate #macro-use

matches

A macro to evaluate, as a boolean, whether an expression matches a pattern

10 releases

Uses old Rust 2015

0.1.10 Jan 21, 2023
0.1.9 Aug 12, 2021
0.1.8 Aug 22, 2018
0.1.7 Jul 19, 2018
0.1.0 Dec 5, 2014

#34 in #evaluate

Download history 1072112/week @ 2026-05-05 1269761/week @ 2026-05-12 1188960/week @ 2026-05-19 1216198/week @ 2026-05-26 1375022/week @ 2026-06-02 1305173/week @ 2026-06-09 1408801/week @ 2026-06-16 1306757/week @ 2026-06-23 1072898/week @ 2026-06-30 1174688/week @ 2026-07-07 1165431/week @ 2026-07-14 1287248/week @ 2026-07-21 1270465/week @ 2026-07-28 1194844/week @ 2026-08-04 1279127/week @ 2026-08-11 1190574/week @ 2026-08-18

5,150,692 downloads per month
Used in 5,439 crates (232 directly)

MIT license

6KB
55 lines

A macro to evaluate, as a boolean, whether an expression matches a pattern.

For users who build using only Rust 1.42 and newer, consider using std::matches, which is included in the standard library prelude and thus is automatically in scope.

Examples

#[macro_use]
extern crate matches;

#[derive(Debug)]
pub enum Foo<T> {
    A,
    B(T),
}

impl<T> Foo<T> {
    pub fn is_b(&self) -> bool {
        matches!(*self, Foo::B(_))
    }
}

impl<T: core::fmt::Debug> Foo<T> {
    pub fn assert_is_b(&self) {
        assert_matches!(&self, Foo::B(_));
    }
}

A macro to evaluate, as a boolean, whether an expression matches a pattern.

For users who build using only Rust 1.42 and newer, consider using std::matches, which is included in the standard library prelude and thus is automatically in scope.

No runtime deps