#build

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

#797 in #build

Download history 421939/week @ 2024-07-01 453400/week @ 2024-07-08 454341/week @ 2024-07-15 462342/week @ 2024-07-22 441573/week @ 2024-07-29 453011/week @ 2024-08-05 514923/week @ 2024-08-12 471827/week @ 2024-08-19 499948/week @ 2024-08-26 468218/week @ 2024-09-02 501080/week @ 2024-09-09 424712/week @ 2024-09-16 502790/week @ 2024-09-23 502508/week @ 2024-09-30 523708/week @ 2024-10-07 506939/week @ 2024-10-14

2,053,273 downloads per month
Used in 5,460 crates (220 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