From: Ian Jackson Date: Sat, 14 May 2022 18:05:34 +0000 (+0100) Subject: shapelib: Break out LibrarySvgNoter X-Git-Tag: otter-1.1.0~180 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e90bc3477058916b108eecc997a03d9d134c6b7a;p=otter.git shapelib: Break out LibrarySvgNoter We're going to want a dummy one for magic library items. Signed-off-by: Ian Jackson --- diff --git a/src/bundles.rs b/src/bundles.rs index 5e674919..1872264d 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -633,9 +633,7 @@ fn parse_bundle(id: Id, instance: &InstanceName, mformat: materials_format::Version, } - impl shapelib::LibrarySource for LibraryInBundle<'_> { - fn catalogue_data(&self) -> &str { &self.catalogue_data } - fn svg_dir(&self) -> String { self.svg_dir.clone() } + impl shapelib::LibrarySvgNoter for LibraryInBundle<'_> { #[throws(shapelib::SubstError)] fn note_svg(&mut self, basename: &GoodItemName, src_name: Result<&str, &shapelib::SubstError>) { @@ -647,12 +645,17 @@ fn parse_bundle(id: Id, instance: &InstanceName, let item = basename.clone(); self.need_svgs.push(SvgNoted { item, src_name }); } + } + impl shapelib::LibrarySource for LibraryInBundle<'_> { + fn catalogue_data(&self) -> &str { &self.catalogue_data } + fn svg_dir(&self) -> String { self.svg_dir.clone() } fn bundle(&self) -> Option { Some(*self.id) } #[throws(materials_format::VersionError)] fn default_materials_format(&self) -> materials_format::Version { self.mformat } + fn svg_noter(&mut self) -> &mut dyn shapelib::LibrarySvgNoter { self } } for LibScanned { libname, dir_inzip, inzip } in libs { diff --git a/src/shapelib.rs b/src/shapelib.rs index e615368f..44f18e3d 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -246,7 +246,7 @@ impl SvgBaseName where T: ?Sized { } impl SvgBaseName where T: Borrow { #[throws(SubstError)] - fn note(src: &mut dyn LibrarySource, i: T, + fn note(src: &mut dyn LibrarySvgNoter, i: T, src_name: Result<&str, &SubstError>) -> Self { src.note_svg(i.borrow(), src_name)?; SvgBaseName(i) @@ -998,16 +998,22 @@ impl Catalogue { } } -pub trait LibrarySource { - fn catalogue_data(&self) -> &str; - fn svg_dir(&self) -> String; +pub trait LibrarySvgNoter { #[throws(SubstError)] fn note_svg(&mut self, _basename: &GoodItemName, _src_name: Result<&str, &SubstError>) { } +} +pub trait LibrarySource: LibrarySvgNoter { + fn catalogue_data(&self) -> &str; + fn svg_dir(&self) -> String; fn bundle(&self) -> Option; fn default_materials_format(&self) -> Result; + + // Sadly dyn_upcast doesn't work because it doesn't support the + // non-'static lifetime on BuiltinLibrary + fn svg_noter(&mut self) -> &mut dyn LibrarySvgNoter; } struct BuiltinLibrary<'l> { @@ -1015,7 +1021,9 @@ struct BuiltinLibrary<'l> { dirname: &'l str, } -impl LibrarySource for BuiltinLibrary<'_> { +impl LibrarySvgNoter for BuiltinLibrary<'_> { +} +impl<'l> LibrarySource for BuiltinLibrary<'l> { fn catalogue_data(&self) -> &str { self.catalogue_data } fn svg_dir(&self) -> String { self.dirname.to_string() } fn bundle(&self) -> Option { None } @@ -1024,6 +1032,8 @@ impl LibrarySource for BuiltinLibrary<'_> { fn default_materials_format(&self) -> materials_format::Version { throw!(MFVE::Other("builtin libraries must have explicit version now!")); } + + fn svg_noter(&mut self) -> &mut dyn LibrarySvgNoter { self } } //---------- reading ---------- @@ -1088,7 +1098,7 @@ pub fn load_catalogue(libname: &str, src: &mut dyn LibrarySource) for fe in gdefn.files.0 { process_files_entry( - src, &mut l, + src.svg_noter(), &mut l, &gdefn.item_prefix, &gdefn.item_suffix, &gdefn.sort, &group, shape_calculable, fe )?; @@ -1175,7 +1185,7 @@ fn format_item_name(item_prefix: &str, fe: &FileData, item_suffix: &str) #[throws(LibraryLoadError)] fn process_files_entry( - src: &mut dyn LibrarySource, l: &mut Catalogue, + src: &mut dyn LibrarySvgNoter, l: &mut Catalogue, item_prefix: &str, item_suffix: &str, sort: &str, group: &Arc, shape_calculable: ShapeCalculable, fe: FileData @@ -1315,7 +1325,8 @@ fn process_files_entry( impl Catalogue { #[throws(LLE)] fn add_item(&mut self, - src: &mut dyn LibrarySource, src_name: Result<&str,&SubstError>, + src: &mut dyn LibrarySvgNoter, + src_name: Result<&str,&SubstError>, item_name: &GoodItemName, catent: CatalogueEntry) { type H<'e,X,Y> = hash_map::Entry<'e,X,Y>;