From e76146b82decebd7a20b48fb1376bdc7c8e0363d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 16 May 2021 00:00:50 +0100 Subject: [PATCH] shapelib: Provide and use ItemEnquiryData -> ItemSpec Signed-off-by: Ian Jackson --- src/bin/otter.rs | 5 +---- src/bin/otterlib.rs | 5 +---- src/shapelib.rs | 9 +++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) 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) { -- 2.30.2