Macro std::assert_matches::assert_matches
pub macro assert_matches { ($left : expr, $(|) ? $($pattern : pat_param) | + $(if $guard : expr) ? $(,) ?) => { ... }, ($left : expr, $(|) ? $($pattern : pat_param) | + $(if $guard : expr) ?, $($arg : tt) +) => { ... }, }
Asserts that an 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.
On panic, this macro will print the value of the expression with its debug representation.
Like assert!
, this macro has a second form, where a custom panic message can be provided.
Examples
#![feature(assert_matches)] use std::assert_matches::assert_matches; let a = 1u32.checked_add(2); let b = 1u32.checked_sub(2); assert_matches!(a, Some(_)); assert_matches!(b, None); let c = Ok("abc".to_string()); assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
© 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/assert_matches/macro.assert_matches.html