chiark / gitweb /
Macro-ise spec::outline
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 21:59:00 +0000 (22:59 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 21:59:00 +0000 (22:59 +0100)
We're going to do more here...

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/spec.rs

index b0a57a688bcbb80bb2ff1692b744685349b2dc9a..a41ff8f7a316c42982f83a5135ba3e38028e5b70 100644 (file)
@@ -257,16 +257,24 @@ pub struct ItemSpec {
 }
 
 mod outline {
-  use super::*;
   use crate::prelude::*;
-  use crate::shapelib::{CircleOutline, RectOutline};
-  #[dyn_upcast(OutlineTrait)]
-  #[enum_dispatch(OutlineTrait)]
-  #[derive(Clone,Debug,Serialize,Deserialize)]
-  #[serde(tag="type")]
-  pub enum Outline {
-    #[serde(rename="Circle")] CircleOutline,
-    #[serde(rename="Rect")]   RectOutline,
+
+  macro_rules! shape_defns { {
+    $( $Shape:ident  $serde:literal  ;)*
+  } => { paste!{
+    $( use crate::shapelib::[< $Shape Outline >]; )*
+    #[dyn_upcast(OutlineTrait)]
+    #[enum_dispatch(OutlineTrait)]
+    #[derive(Clone,Debug,Serialize,Deserialize)]
+    #[serde(tag="type")]
+    pub enum Outline { $(
+      #[serde(rename=$serde)] [< $Shape Outline >],
+    )* }
+  } } }
+
+  shape_defns! {
+    Circle "Circle";
+    Rect   "Rect"  ;
   }
 }
 pub use outline::*;