Macro std::matches1.42.0[][src]

macro_rules! matches {
    ($expression : expr, $(|) ? $($pattern : pat_param) | + $(if $guard : expr) ?
 $(,) ?) => { ... };
}
Expand description

返回给定表达式是否与任何给定模式匹配。

像在 match 表达式中一样,可以在模式后跟 if 和可以访问由模式绑定的名称的保护表达式。

Examples

let foo = 'f';
assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));

let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2));
Run