chiark / gitweb /
dice: Break out occ_label
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 13:32:25 +0000 (14:32 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 Apr 2022 13:26:23 +0000 (14:26 +0100)
We are going to want to call this for situations where we have an
OccultSpec but not an occultable image.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/dice.rs

index 809cf1de742888f278c39cfe255182cf42d63aed..69ff21d9319ae36dc43577beba7c1d878b8daa7c 100644 (file)
@@ -171,18 +171,23 @@ impl PieceSpec for Spec {
     };
     let _state: &mut State = gpc.xdata_mut(|| initial_state)?;
 
+    let occ_label = |occ: &OccultSpec| -> String {
+      if occ.label == "" && labels.iter().any(|l| l != "") {
+        "?".into()
+      } else {
+        occ.label.clone()
+      }
+    };
+
     let occultable = match (img_occultable, &self.occult) {
       (None, None) => None,
       (None, Some(_occ)) => {
         throw!(SpecError::UnusedOccultLabel)
       },
       (Some((image_occ_ilk, image_occ_image)), occ) => {
-        let occ = occ.clone().unwrap_or_default();
-        let occ_label = if occ.label == "" && labels.iter().any(|l| l != "") {
-          "?".into()
-        } else {
-          occ.label
-        };
+        let default_occ = default();
+        let occ = occ.as_ref().unwrap_or(&default_occ);
+        let occ_label = occ_label(occ);
 
         let our_ilk =
           // We need to invent an ilk to allow coalescing of similar