How do I create a HashMap with type erased keys?
问题 I want to be able to use a variety of different types as keys in a HashMap , all of which would implement Hash . This seems like it should be possible: from reading the docs it seems that every Hasher will produce a u64 result, so they eventually get reduced down to a common type. Effectively I want to do: use std::{collections::HashMap, hash::Hash}; fn x(_: HashMap<Box<dyn Hash>, ()>) {} which I'm not allowed to do: error[E0038]: the trait `std::hash::Hash` cannot be made into an object -->