use std::collections::HashSet; use std::hash::{Hash, Hasher}; use std::collections::hash_map::DefaultHasher; struct HashOnlySet { set: HashSet, } impl HashOnlySet { fn new() -> HashOnlySet { HashOnlySet { set: HashSet::new() } } fn insert(&mut self, item: &T) -> bool { let hash = Self::hash_item(item); self.set.insert(hash) } fn contains(&self, item: &T) -> bool { let hash = Self::hash_item(item); self.set.contains(&hash) } fn hash_item(item: &T) -> u64 { let mut hasher = DefaultHasher::new(); item.hash(&mut hasher); hasher.finish() } } fn main() { let mut set = HashOnlySet::new(); set.insert(&"Hello, world!"); println!("Contains 'Hello, world!': {}", set.contains(&"Hello, world!")); println!("Contains 'Goodbye, world!': {}", set.contains(&"Goodbye, world!")); }