1use _std::{collections::HashSet, hash::Hash};
6
7use crate::{Get, Insert, IntoIter, Keyed, Map, Remove};
8
9impl<K> Map for HashSet<K> {
10 type Item = ();
11}
12
13impl<K> Keyed for HashSet<K> {
14 type Key = K;
15}
16
17impl<K: Eq + Hash> Get<K> for HashSet<K> {
18 #[inline(always)]
19 fn get(&self, key: &K) -> Option<&()> {
20 HashSet::get(self, key).map(|_| &())
21 }
22}
23
24impl<K: Eq + Hash> Insert<K> for HashSet<K> {
25 #[inline(always)]
26 fn insert(&mut self, key: K, _value: ()) {
27 HashSet::insert(self, key);
28 }
29}
30
31impl<K: Eq + Hash> Remove<K> for HashSet<K> {
32 #[inline(always)]
33 fn remove(&mut self, key: &K) -> Option<()> {
34 HashSet::remove(self, key).then_some(())
35 }
36}
37
38pub struct MapIntoIter<K>(_std::collections::hash_set::IntoIter<K>);
39
40impl<K> Iterator for MapIntoIter<K> {
41 type Item = (K, ());
42
43 fn next(&mut self) -> Option<Self::Item> {
44 self.0.next().map(|k| (k, ()))
45 }
46}
47
48impl<K> IntoIter<K> for HashSet<K> {
49 type IntoIter = MapIntoIter<K>;
50
51 fn into_iter(self) -> MapIntoIter<K> {
52 MapIntoIter(IntoIterator::into_iter(self))
53 }
54}