title: How do I create a HashMap with type erased keys?
body: <p>I want to be able to use a variety of different types as keys in a <code>HashMap</code>, all of which would implement <code>Hash</code>. This seems like it should be possible: from reading the docs it seems that every <code>Hasher</code> will produce a <code>u64</code> result, so they eventually get reduced down to a common type. Effectively I want to do:</p>
  <pre class="lang-rust prettyprint-override"><code>use std::{collections::HashMap, hash::Hash};
  
  fn x(_: HashMap&lt;Box&lt;dyn Hash&gt;, ()&gt;) {}
  </code></pre>
  <p>which I'm not allowed to do:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0038]: the trait `std::hash::Hash` cannot be made into an object
     --&gt; src/lib.rs:3:9
      |
  3   | fn x(_: HashMap&lt;Box&lt;dyn Hash&gt;, ()&gt;) {}
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::hash::Hash` cannot be made into an object
  </code></pre>
  <p>It seems like I <em>could</em> create a <code>Hasher</code> (e.g. <code>RandomState</code>), use that to manually calculate hash values, then store the <code>u64</code> result in a <code>HashMap&lt;u64, _&gt;</code> but that seems kind of overly complex. I don't ever want to get the key values back out again, I just need to be able to compare the hash values. Is there a <code>HashMap</code> alternative I'm not aware of? Or am I looking at this in a totally wrong way?</p>