chiark / gitweb /
wip keydata reorg
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Jun 2020 12:08:40 +0000 (13:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Jun 2020 12:08:40 +0000 (13:08 +0100)
src/gamestate.rs
src/imports.rs
src/keydata.rs [new file with mode: 0644]
src/lib.rs

index 98ddebe0c6930a0d131b3691c09938250d66e3d6..d8e4d26eef7c0b39df06214f1cdab16b243f1777 100644 (file)
@@ -23,14 +23,7 @@ impl Display for VisiblePieceId {
     write!(f, "{}.{}", self.0 >> 32, self.0 & 0xffffffff)
   }
 }
-impl Debug for VisiblePieceId {
-  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
-    <Self as Display>::fmt(self, f)
-  }
-}
-impl From<VisiblePieceId> for String {
-  fn from(p: VisiblePieceId) -> String { format!("{}",p) }
-}
+display_consequential_impls!{VisiblePieceId}
 
 impl TryFrom<&str> for VisiblePieceId {
   type Error = AE;
index 08b5e331075ee0182ca884480efa0653452defae..61070b8cc706df06ede77e6ece62e46433ff9334 100644 (file)
@@ -33,6 +33,7 @@ pub use index_vec::{define_index_type,index_vec,IndexVec};
 pub use crate::global::*;
 pub use crate::gamestate::*;
 pub use crate::pieces::*;
+pub use crate::keydata::*;
 
 pub type E = anyhow::Error;
 pub type AE = anyhow::Error;
diff --git a/src/keydata.rs b/src/keydata.rs
new file mode 100644 (file)
index 0000000..9352892
--- /dev/null
@@ -0,0 +1,16 @@
+
+#[macro_export]
+macro_rules! display_consequential_impls {
+  ( $x:path ) => {
+    impl From<$x> for String {
+      fn from(p : $x) -> String { format!("{}",p) }
+    }
+    impl Debug for $x {
+      fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+        <Self as Display>::fmt(self, f)
+      }
+    }
+  }
+}
+
+pub use crate::display_consequential_impls; // this is madness!
index 62de69ea2a2713f751efe1679a27df4187c5bf1a..5096c9eee82635eeca3ba3766e02c7b321beb9bf 100644 (file)
@@ -3,3 +3,4 @@ pub mod imports;
 pub mod global;
 pub mod pieces;
 pub mod gamestate;
+pub mod keydata;