chiark / gitweb /
if_let: Provide a way to get at the error
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 May 2021 22:24:52 +0000 (23:24 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 13:58:58 +0000 (14:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
base/misc.rs

index faa47bc4018bedb8a34ad7a47f15700ec3e90639..66c98ffff129c7fe94dee4be9aed7f41fc35b8b4 100644 (file)
@@ -67,6 +67,14 @@ pub fn space_rect_attrs(table_size: PosC<f64>) -> SvgAttrs {
 
 #[macro_export]
 macro_rules! if_let {
+  { $($variant:ident)::+ ($binding:pat) = $input:expr;
+    match $($otherwise:tt)*
+  } => {
+    let $binding = match $input {
+      $($variant)::+  (y) => y,
+      $($otherwise)*,
+    };
+  };
   { $($variant:ident)::+ ($binding:pat) = $input:expr;
     else $($otherwise:tt)*
   } => {