chiark / gitweb /
utils: provide matches_doesnot
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Mar 2021 22:16:24 +0000 (22:16 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Mar 2021 22:16:24 +0000 (22:16 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/utils.rs

index a7ab450445867c2e156dbba6661f03b785271104..6169c1629a92a7998f69a4a339df26c80f0b5e84 100644 (file)
@@ -353,6 +353,16 @@ impl<T,U,E,F> IteratorExt<U,E,F> 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