From 8b69a174a2b309ea254b32a6c234c09308aacb52 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 7 Mar 2021 22:16:24 +0000 Subject: [PATCH] utils: provide matches_doesnot Signed-off-by: Ian Jackson --- src/utils.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index a7ab4504..6169c162 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -353,6 +353,16 @@ impl IteratorExt for T where } } +#[macro_export] +macro_rules! matches_doesnot { + ($v:expr; $y:pat, ! $n:pat) => { match $v { $y => true, $n => false } } +} + +#[test] +fn matches_doesnot_test() { + assert!( matches_doesnot!( Some(42); Some(_), ! None) ); +} + #[macro_export] macro_rules! dbgc { // NOTE: We cannot use `concat!` to make a static string as a format argument -- 2.30.2