On this page
Macro std::matches
macro_rules! matches {
($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => { ... };
}
Returns whether the given expression matches any of the given patterns.
Like in a match
expression, the pattern can be optionally followed by if
and a guard expression that has access to names bound by the pattern.
Examples
let foo = 'f';
assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2));
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/macro.matches.html