Movatterモバイル変換


[0]ホーム

URL:


matches

std

Macromatches 

1.42.0 ·Source
macro_rules! matches {    ($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => { ... };}
Expand description

Returns whether the given expression matches the provided pattern.

The pattern syntax is exactly the same as found in a match arm. The optional if guard can beused to add additional checks that must be true for the matched value, otherwise this macro willreturnfalse.

When testing that a value matches a pattern, it’s generally preferable to useassert_matches! as it will print the debug representation of the value if the assertionfails.

§Examples

letfoo ='f';assert!(matches!(foo,'A'..='Z'|'a'..='z'));letbar =Some(4);assert!(matches!(bar,Some(x)ifx >2));

[8]ページ先頭

©2009-2026 Movatter.jp