From: Ian Jackson Date: Fri, 13 May 2022 21:31:55 +0000 (+0100) Subject: shapelib: Split find_then from find_load X-Git-Tag: otter-1.1.0~209 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=522bc965abde5756a5f254c5445b298bd04001c1;p=otter.git shapelib: Split find_then from find_load This is preparatory to making the catalogue capable of holding magic pieces. Signed-off-by: Ian Jackson --- diff --git a/src/shapelib.rs b/src/shapelib.rs index 5182f85f..d02c8d76 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -413,14 +413,25 @@ impl From for SpecLoaded { impl ItemSpec { #[throws(SpecError)] - fn find_load(&self, ig: &Instance, depth: SpecDepth) -> ItemSpecLoaded { + fn find_then(&self, ig: &Instance, then: F) -> T + where F: FnOnce(&Catalogue, &SvgBaseName, &ItemData) + -> Result + { let regs = ig.all_shapelibs(); let libs = regs.lib_name_lookup(&self.lib)?; let (lib, (item, idata)) = libs.iter().rev().find_map( |lib| Some((lib, lib.items.get_key_value(self.item.as_str())?)) ) .ok_or_else(|| SpE::LibraryItemNotFound(self.clone()))?; - lib.load1(idata, &self.lib, item.unnest::(), ig, depth)? + then(lib, item, idata)? + } + + #[throws(SpecError)] + fn find_load(&self, ig: &Instance, + depth: SpecDepth) -> ItemSpecLoaded { + self.find_then(ig, |lib, item, idata| { + lib.load1(idata, &self.lib, item.unnest::(), ig, depth) + })? } fn from_strs(lib: &L, item: &I) -> Self