chiark / gitweb /
impl slotmap::Key
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Jun 2020 12:51:24 +0000 (13:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Jun 2020 12:51:24 +0000 (13:51 +0100)
src/keydata.rs

index 60e2e2a7ec057afc83a562eeaf110a44d7935004..44b2ea51b95a3f7dd7b6a164aa0027688dabbbeb 100644 (file)
@@ -37,7 +37,8 @@ pub fn slotkey_write(k : SKD, sep : char, f : &mut fmt::Formatter) {
 #[macro_export]
 macro_rules! visible_slotmap_key {
   ( $x:ident ) => {
-    #[derive(Copy,Clone,Serialize,Deserialize)]
+
+    #[derive(Copy,Clone,Eq,PartialEq,Ord,PartialOrd,Serialize,Deserialize)]
     #[serde(into="String")]
     #[serde(try_from="&str")]
     pub struct $x(pub slotmap::KeyData);
@@ -54,6 +55,16 @@ macro_rules! visible_slotmap_key {
         VisiblePieceId(slotkey_parse(s,'.')?)
       }
     }
+
+    impl slotmap::Key for $x { }
+    impl From<slotmap::KeyData> for $x {
+      fn from(d : slotmap::KeyData) -> Self { $x(d) }
+    }
+    impl From<$x> for slotmap::KeyData {
+      fn from(p : $x) -> Self {
+        p.0
+      }
+    }
   }
 }
 pub use crate::visible_slotmap_key; // this is madness!