matches

Macro matches

Source
macro_rules! matches {
    ($expression:expr, $($pattern:tt)+) => { ... };
}
Expand description

Check if an expression matches a refutable pattern.

Syntax: matches!( expression , pattern )

Return a boolean, true if the expression matches the pattern, false otherwise.

ยงExamples

#[macro_use]
extern crate matches;

pub enum Foo<T> {
    A,
    B(T),
}

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

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