From: Ian Jackson Date: Sun, 7 Mar 2021 22:16:24 +0000 (+0000) Subject: utils: provide matches_doesnot X-Git-Tag: otter-0.4.0~233 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8b69a174a2b309ea254b32a6c234c09308aacb52;p=otter.git utils: provide matches_doesnot Signed-off-by: Ian Jackson --- 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