Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

Cratematches

Source
Expand description

A macro to evaluate, as a boolean, whether an expression matches a pattern.

For users who build using only Rust 1.42 and newer, consider usingstd::matches, whichis included in thestandard library prelude and thus is automatically in scope.

§Examples

#[macro_use]extern cratematches;#[derive(Debug)]pub enumFoo<T> {    A,    B(T),}impl<T> Foo<T> {pub fnis_b(&self) -> bool {matches!(*self, Foo::B(_))    }}impl<T: core::fmt::Debug> Foo<T> {pub fnassert_is_b(&self) {assert_matches!(&self, Foo::B(_));    }}

Macros§

assert_matches
Assert that an expression matches a refutable pattern.
debug_assert_matches
Assert that an expression matches a refutable pattern using debug assertions.
matches
Check if an expression matches a refutable pattern.

[8]ページ先頭

©2009-2025 Movatter.jp