chiark / gitweb /
if_let: Remove the "match" from the general case
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 14:57:36 +0000 (15:57 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 14:57:36 +0000 (15:57 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
base/misc.rs
src/bundles.rs

index b4cb57cd10d8512b5cbb9ab22a80822bbad36902..c34a258f7c5d287d86accece0001a937ce1b2ab2 100644 (file)
@@ -68,19 +68,19 @@ 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)*
+    else $($otherwise:tt)*
   } => {
     let $binding = match $input {
-      $($variant)::+  (y) => y,
-      $($otherwise)*,
+      $($variant)::+ (y) => y,
+      _ => { $($otherwise)* },
     };
   };
   { $($variant:ident)::+ ($binding:pat) = $input:expr;
-    else $($otherwise:tt)*
+    $($otherwise:tt)*
   } => {
     let $binding = match $input {
-      $($variant)::+ (y) => y,
-      _ => { $($otherwise)* },
+      $($variant)::+  (y) => y,
+      $($otherwise)*,
     };
   };
   { $($variant:ident)::+ {$binding:ident} = $input:expr;
@@ -92,7 +92,7 @@ macro_rules! if_let {
     };
   };
   { $($variant:ident)::+ {$binding:ident} = $input:expr;
-    match $($otherwise:tt)*
+    $($otherwise:tt)*
   } => {
     let $binding = match $input {
       $($variant)::+ { $binding } => $binding,
index 789db9a94db96eddef0d2813987dbd69a866e1d8..09e06e6160b9dcdad7c58e87f0a8a7e725368b95 100644 (file)
@@ -950,7 +950,7 @@ impl InstanceBundles {
   pub fn truncate_all_besteffort(instance: &InstanceName) {
     if_let!{
       Ok(bundles) = InstanceBundles::scan_game_bundles(instance);
-      match Err(e) => {
+      Err(e) => {
         error!("failed to scan game bundles for {}: {}", instance, e);
         return;
       }
@@ -958,14 +958,14 @@ impl InstanceBundles {
     for entry in bundles {
       if_let!{
         Ok((fpath,_what)) = entry;
-        match Err(e) => {
+        Err(e) => {
           error!("failed to make sense of a pathname for {}: {}", instance, e);
           continue;
         }
       };
       if_let!{
         Ok(_) = File::create(&fpath);
-        match Err(e) => {
+        Err(e) => {
           warn!("failed to truncate a bundle for {}: {}: {}",
                 instance, fpath, e);
           continue;