#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

#39 in #whether

Download history 543507/week @ 2024-10-25 507469/week @ 2024-11-01 528603/week @ 2024-11-08 544377/week @ 2024-11-15 430874/week @ 2024-11-22 453075/week @ 2024-11-29 566585/week @ 2024-12-06 500798/week @ 2024-12-13 224926/week @ 2024-12-20 207615/week @ 2024-12-27 444529/week @ 2025-01-03 538352/week @ 2025-01-10 434907/week @ 2025-01-17 451643/week @ 2025-01-24 548292/week @ 2025-01-31 581648/week @ 2025-02-07

2,118,197 downloads per month
Used in 5,522 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