fork download
  1. use std::any::TypeId;
  2. use std::collections::HashMap;
  3. use std::{collections::HashSet, hash::Hash};
  4. #[derive(Debug)]
  5. struct BinaryBox(TypeId, Box<[u8]>);
  6. impl PartialEq for BinaryBox {
  7. fn eq(&self, other: &Self) -> bool {
  8. self.0 == other.0 && self.1 == other.1
  9. }
  10. }
  11. impl Eq for BinaryBox {}
  12. impl Hash for BinaryBox {
  13. fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
  14. self.0.hash(state);
  15. self.1.hash(state);
  16. }
  17. }
  18. fn main() {
  19. let mut set = HashMap::<BinaryBox, BinaryBox>::new();
  20. set.insert(
  21. BinaryBox(
  22. TypeId::of::<&str>(),
  23. "Key".as_bytes().to_vec().into_boxed_slice(),
  24. ),
  25. BinaryBox(TypeId::of::<i32>(), Box::new(123i32.to_ne_bytes())),
  26. );
  27. println!("{:?}", set);
  28. }
  29.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
{BinaryBox(TypeId { t: 1229646359891580772 }, [75, 101, 121]): BinaryBox(TypeId { t: 13431306602944299956 }, [123, 0, 0, 0])}