From: Ian Jackson Date: Sat, 15 May 2021 23:00:50 +0000 (+0100) Subject: shapelib: Provide and use ItemEnquiryData -> ItemSpec X-Git-Tag: otter-0.6.0~245 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e76146b82decebd7a20b48fb1376bdc7c8e0363d;p=otter.git shapelib: Provide and use ItemEnquiryData -> ItemSpec Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index b3091326..23de4f49 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -1287,10 +1287,7 @@ mod library_add { } } }; - let spec = shapelib::ItemSpec { - lib: it.lib.libname.clone(), - item: it.itemname.as_str().to_owned(), - }; + let spec = ItemSpec::from(it); let spec = PiecesSpec { pos: Some(pos), posd: None, count: Some(1), face: None, pinned: Some(false), diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index d2769acf..dac2a454 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -93,10 +93,7 @@ fn preview(items: Vec) { } let mut pieces: Vec = items.into_iter().map(|it| { - let spec = ItemSpec { - lib: it.lib.libname.into(), - item: it.itemname.into(), - }; + let spec = ItemSpec::from(&it); let sortkey = it.sortkey; (||{ let (p, _occultable) = spec.clone() diff --git a/src/shapelib.rs b/src/shapelib.rs index 73ad43e8..48de1858 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -228,6 +228,15 @@ pub struct ItemEnquiryData { pub f0bbox: Rect, } +impl From<&ItemEnquiryData> for ItemSpec { + fn from(it: &ItemEnquiryData) -> ItemSpec { + ItemSpec { + lib: it.lib.libname.clone(), + item: it.itemname.as_str().to_owned(), + } + } +} + impl Display for ItemEnquiryData { #[throws(fmt::Error)] fn fmt(&self, f: &mut Formatter) {