SHARE
TWEET

Untitled

a guest Oct 10th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::collections::hash_map::DefaultHasher;
  2. use std::hash::{Hash};
  3.  
  4. pub trait Hash2 {
  5.     fn hash2(&self, state: &mut DefaultHasher);
  6. }
  7.  
  8. pub fn doit(h: &mut DefaultHasher, a: &dyn Hash2, b: &dyn Hash2) -> bool {
  9.     a.hash2(h) == b.hash2(h)
  10. }
  11.  
  12. impl<T> Hash2 for T
  13. where
  14.     T: Hash,
  15. {
  16.     fn hash2(&self, state: &mut DefaultHasher) {
  17.         self.hash(state)
  18.     }
  19. }
  20.  
  21. #[test]
  22. fn check() {
  23.     let mut hasher = DefaultHasher::new();
  24.     assert!(doit(&mut hasher, &5, &5));
  25.     assert_false!(doit(&mut hasher, &5, &5.0));
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top