From: Ian Jackson Date: Sat, 16 Apr 2022 13:32:25 +0000 (+0100) Subject: dice: Break out occ_label X-Git-Tag: otter-1.1.0~517 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fbdfacbf6eeb51bc1da8ece1c187f7f75fe82f07;p=otter.git dice: Break out occ_label 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 --- diff --git a/src/dice.rs b/src/dice.rs index 809cf1de..69ff21d9 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -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