#expression #pattern #evaluate #boolean #whether #debugging #match

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

#2874 in Rust patterns

Download history 407087/week @ 2024-01-05 398501/week @ 2024-01-12 437011/week @ 2024-01-19 415098/week @ 2024-01-26 411368/week @ 2024-02-02 423283/week @ 2024-02-09 407454/week @ 2024-02-16 461742/week @ 2024-02-23 455135/week @ 2024-03-01 436421/week @ 2024-03-08 427950/week @ 2024-03-15 441432/week @ 2024-03-22 435836/week @ 2024-03-29 416975/week @ 2024-04-05 428955/week @ 2024-04-12 364552/week @ 2024-04-19

1,729,313 downloads per month
Used in 6,008 crates (222 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.


lib.rs:

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(_));
    }
}

No runtime deps