1use crate::*;
4use collection_tools::HashSet;
5
6#[allow(clippy::implicit_hasher)]
7impl<K> Collection for HashSet<K>
8where
9 K: core::cmp::Eq + core::hash::Hash,
10{
11 type Entry = K;
12 type Val = K;
13
14 #[inline(always)]
15 fn entry_to_val(e: Self::Entry) -> Self::Val {
16 e
17 }
18}
19
20#[allow(clippy::implicit_hasher)]
21impl<K> CollectionAdd for HashSet<K>
22where
23 K: core::cmp::Eq + core::hash::Hash,
24{
25 #[inline(always)]
29 fn add(&mut self, e: Self::Entry) -> bool {
30 self.insert(e)
31 }
32}
33
34#[allow(clippy::implicit_hasher)]
35impl<K> CollectionAssign for HashSet<K>
36where
37 K: core::cmp::Eq + core::hash::Hash,
38{
39 fn assign<Elements>(&mut self, elements: Elements) -> usize
42 where
43 Elements: IntoIterator<Item = Self::Entry>,
44 {
45 let initial_len = self.len();
46 self.extend(elements);
47 self.len() - initial_len
48 }
49}
50
51#[allow(clippy::implicit_hasher)]
52impl<K> CollectionValToEntry<K> for HashSet<K>
53where
54 K: core::cmp::Eq + core::hash::Hash,
55{
56 type Entry = K;
57 #[inline(always)]
58 fn val_to_entry(val: K) -> Self::Entry {
59 val
60 }
61}
62
63#[allow(clippy::implicit_hasher)]
94impl<K> Storage for HashSet<K>
95where
96 K: ::core::cmp::Eq + ::core::hash::Hash,
97{
98 type Preformed = HashSet<K>;
100}
101
102#[allow(clippy::implicit_hasher)]
103impl<K> StoragePreform for HashSet<K>
104where
105 K: ::core::cmp::Eq + ::core::hash::Hash,
106{
107 fn preform(self) -> Self::Preformed {
109 self
110 }
111}
112
113#[derive(Debug, Default)]
130pub struct HashSetDefinition<K, Context = (), Formed = HashSet<K>, End = ReturnStorage>
131where
132 K: ::core::cmp::Eq + ::core::hash::Hash,
133 End: FormingEnd<HashSetDefinitionTypes<K, Context, Formed>>,
134{
135 _phantom: core::marker::PhantomData<(K, Context, Formed, End)>,
136}
137
138impl<K, Context, Formed, End> FormerDefinition for HashSetDefinition<K, Context, Formed, End>
139where
140 K: ::core::cmp::Eq + ::core::hash::Hash,
141 End: FormingEnd<HashSetDefinitionTypes<K, Context, Formed>>,
142{
143 type Storage = HashSet<K>;
144 type Formed = Formed;
145 type Context = Context;
146
147 type Types = HashSetDefinitionTypes<K, Context, Formed>;
148 type End = End;
149}
150
151#[derive(Debug, Default)]
161pub struct HashSetDefinitionTypes<K, Context = (), Formed = HashSet<K>> {
162 _phantom: core::marker::PhantomData<(K, Context, Formed)>,
163}
164
165impl<K, Context, Formed> FormerDefinitionTypes for HashSetDefinitionTypes<K, Context, Formed>
166where
167 K: ::core::cmp::Eq + ::core::hash::Hash,
168{
169 type Storage = HashSet<K>;
170 type Formed = Formed;
171 type Context = Context;
172}
173
174impl<K, Context, Formed> FormerMutator for HashSetDefinitionTypes<K, Context, Formed> where K: ::core::cmp::Eq + ::core::hash::Hash
177{}
178
179#[allow(clippy::implicit_hasher)]
182impl<K, Definition> EntityToFormer<Definition> for HashSet<K>
183where
184 K: ::core::cmp::Eq + ::core::hash::Hash,
185 Definition: FormerDefinition<
186 Storage = HashSet<K>,
187 Types = HashSetDefinitionTypes<
188 K,
189 <Definition as definition::FormerDefinition>::Context,
190 <Definition as definition::FormerDefinition>::Formed,
191 >,
192 >,
193 Definition::End: forming::FormingEnd<Definition::Types>,
194{
195 type Former = HashSetFormer<K, Definition::Context, Definition::Formed, Definition::End>;
196}
197
198#[allow(clippy::implicit_hasher)]
199impl<K> crate::EntityToStorage for HashSet<K>
200where
201 K: ::core::cmp::Eq + ::core::hash::Hash,
202{
203 type Storage = HashSet<K>;
204}
205
206#[allow(clippy::implicit_hasher)]
207impl<K, Context, Formed, End> crate::EntityToDefinition<Context, Formed, End> for HashSet<K>
208where
209 K: ::core::cmp::Eq + ::core::hash::Hash,
210 End: crate::FormingEnd<HashSetDefinitionTypes<K, Context, Formed>>,
211{
212 type Definition = HashSetDefinition<K, Context, Formed, End>;
213 type Types = HashSetDefinitionTypes<K, Context, Formed>;
214}
215
216#[allow(clippy::implicit_hasher)]
217impl<K, Context, Formed> crate::EntityToDefinitionTypes<Context, Formed> for HashSet<K>
218where
219 K: ::core::cmp::Eq + ::core::hash::Hash,
220{
221 type Types = HashSetDefinitionTypes<K, Context, Formed>;
222}
223
224pub type HashSetFormer<K, Context, Formed, End> = CollectionFormer<K, HashSetDefinition<K, Context, Formed, End>>;
233
234pub trait HashSetExt<K>: sealed::Sealed
243where
244 K: ::core::cmp::Eq + ::core::hash::Hash,
245{
246 fn former() -> HashSetFormer<K, (), HashSet<K>, ReturnStorage>;
248}
249
250#[allow(clippy::implicit_hasher)]
251impl<K> HashSetExt<K> for HashSet<K>
252where
253 K: ::core::cmp::Eq + ::core::hash::Hash,
254{
255 #[allow(clippy::default_constructed_unit_structs)]
256 fn former() -> HashSetFormer<K, (), HashSet<K>, ReturnStorage> {
257 HashSetFormer::<K, (), HashSet<K>, ReturnStorage>::new(ReturnStorage::default())
258 }
259}
260
261mod sealed {
262 use super::HashSet;
263 pub trait Sealed {}
264 impl<K> Sealed for HashSet<K> {}
265}