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