use std::hash::{Hash, Hasher}; use AsBytes; /// A structure that implements `Eq` and is hashable even if the wrapped data implements only /// `PartialEq`. #[derive(PartialEq, Clone, Debug)] pub struct HashablePartialEq { value: T, } impl HashablePartialEq { /// Creates a new `HashablePartialEq`. This is unsafe because you must be sure that you really /// want to transform the wrapped object's partial equality to an equivalence relation. pub unsafe fn new(value: T) -> HashablePartialEq { HashablePartialEq { value: value } } /// Gets the wrapped value. pub fn unwrap(self) -> T { self.value } } impl Eq for HashablePartialEq {} impl Hash for HashablePartialEq { #[inline] fn hash(&self, state: &mut H) { state.write(self.value.as_bytes()) } }