title: How to implement serde's Deserialize & Serialize for an external type?
body: <p>I'm trying to implement <code>Serialize</code> &amp; <code>Deserialize</code> for an external enum and I have no idea how. It has <code>From&lt;u64&gt;</code> so all I want to do is just have that object serialize with that.</p>
  <pre class="lang-rust prettyprint-override"><code>#[derive(Serialize, Deserialize)]
  pub struct ImageBinds {
      binds: HashMap&lt;KeybdKey, Vec&lt;u8&gt;&gt;, // KeybdKey doesn't implement serialize
  }
  
  // won't compile with this:
  // only traits defined in the current crate can be implemented for arbitrary types
  // impl doesn't use only types from inside the current crate
  // I understand the orphan rule and all that but I have no idea how else I'd implement it
  // I've looked at serde remote stuff and I cannot work out how to do it with an enum without
  // literally just copying the whole crate into my scope which is stupid
  impl Serialize for KeybdKey {
      fn serialize&lt;S: Serializer&gt;(&amp;self, serializer: S) -&gt; Result&lt;S::Ok, S::Error&gt; {
          serializer.serialize_u64(u64::from(*self))
      }
  }
  </code></pre>
  <p><a href="https://docs.rs/inputbot/0.5.0/inputbot/enum.KeybdKey.html" rel="noreferrer"><code>KeybdKey</code></a> is from the <code>inputbot</code> crate.</p>