#pattern #expression #whether #evaluate #boolean #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

#37 in #whether

Download history 521231/week @ 2024-11-17 404433/week @ 2024-11-24 484436/week @ 2024-12-01 577116/week @ 2024-12-08 466848/week @ 2024-12-15 188488/week @ 2024-12-22 244410/week @ 2024-12-29 476373/week @ 2025-01-05 531330/week @ 2025-01-12 423780/week @ 2025-01-19 454816/week @ 2025-01-26 603876/week @ 2025-02-02 531461/week @ 2025-02-09 461914/week @ 2025-02-16 551137/week @ 2025-02-23 503649/week @ 2025-03-02

2,096,989 downloads per month
Used in 5,528 crates (221 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