chiark / gitweb /
shapelib: Provide and use ItemEnquiryData -> ItemSpec
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 May 2021 23:00:50 +0000 (00:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 May 2021 23:32:13 +0000 (00:32 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/bin/otterlib.rs
src/shapelib.rs

index b30913264594a50ad5c43fbdd452a5777bb72949..23de4f49503762546464ccd5215213b58fdd93b1 100644 (file)
@@ -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),
index d2769acf31b1ea2e1cf6fa677572abc956b02dce..dac2a454a50d3b769d306780451dd4b88904b3a1 100644 (file)
@@ -93,10 +93,7 @@ fn preview(items: Vec<ItemForOutput>) {
   }
 
   let mut pieces: Vec<Prep> = 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()
index 73ad43e8eabe9f733a79a1caa1c05e67506a0fa1..48de1858d14f989e201d4ef219cafc59447c5250 100644 (file)
@@ -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) {