data_structure_traits/collections/
hash_set.rs

1macro_rules! impl_hash_set {
2    ($HashSet:ident) => {
3        use core::borrow::Borrow;
4        use core::hash::{BuildHasher, Hash};
5
6        use super::super::super::*;
7
8        impl<V, S> Collection for $HashSet<V, S>
9        where
10            V: Eq + Hash,
11            S: BuildHasher,
12        {
13            #[inline(always)]
14            fn len(&self) -> usize {
15                $HashSet::<V, S>::len(self)
16            }
17        }
18
19        impl<V, S> CollectionMut for $HashSet<V, S>
20        where
21            V: Eq + Hash,
22            S: BuildHasher,
23        {
24            #[inline(always)]
25            fn clear(&mut self) {
26                $HashSet::<V, S>::drain(self);
27            }
28        }
29
30        impl<V, S> Create<V> for $HashSet<V, S>
31        where
32            V: Eq + Hash,
33            S: Default + BuildHasher,
34        {
35            #[inline(always)]
36            fn create() -> Self {
37                $HashSet::<V, S>::default()
38            }
39            #[inline(always)]
40            fn create_with_capacity(_: usize) -> Self {
41                $HashSet::<V, S>::default()
42            }
43
44            #[inline(always)]
45            fn add_element(mut self, value: V) -> Self {
46                $HashSet::<V, S>::insert(&mut self, value);
47                self
48            }
49        }
50
51        impl<'a, Q, V, S> Get<&'a Q> for $HashSet<V, S>
52        where
53            Q: Eq + Hash + ?Sized,
54            V: Eq + Hash + Borrow<Q>,
55            S: BuildHasher,
56        {
57            type Output = V;
58
59            #[inline(always)]
60            fn get(&self, q: &Q) -> Option<&Self::Output> {
61                $HashSet::get(self, q)
62            }
63        }
64
65        impl<V, S> Add<V> for $HashSet<V, S>
66        where
67            V: Eq + Hash,
68            S: BuildHasher,
69        {
70            type Output = bool;
71
72            #[inline(always)]
73            fn add(&mut self, v: V) -> Self::Output {
74                $HashSet::<V, S>::insert(self, v)
75            }
76        }
77    };
78}
79
80#[cfg(feature = "hashmap_core")]
81mod __impl_hash_set {
82    use hashmap_core::HashSet;
83    impl_hash_set!(HashSet);
84}
85
86#[cfg(feature = "std")]
87mod __impl_hash_set {
88    use std::collections::hash_set::HashSet;
89    impl_hash_set!(HashSet);
90}