1use crate::*;
4use collection_tools::HashSet;
5
6impl< K > Collection for HashSet< K >
7where
8 K : core::cmp::Eq + core::hash::Hash,
9{
10 type Entry = K;
11 type Val = K;
12
13 #[ inline( always ) ]
14 fn entry_to_val( e : Self::Entry ) -> Self::Val
15 {
16 e
17 }
18
19}
20
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 {
31 self.insert( e )
32 }
33
34}
35
36impl< K > CollectionAssign for HashSet< K >
37where
38 K : core::cmp::Eq + core::hash::Hash,
39{
40 fn assign< Elements >( &mut self, elements : Elements ) -> usize
43 where
44 Elements : IntoIterator< Item = Self::Entry >
45 {
46 let initial_len = self.len();
47 self.extend( elements );
48 self.len() - initial_len
49 }
50}
51
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 {
60 val
61 }
62}
63
64impl< K > Storage
95for HashSet< K >
96where
97 K : ::core::cmp::Eq + ::core::hash::Hash,
98{
99 type Preformed = HashSet< K >;
101}
102
103impl< K > StoragePreform
104for HashSet< K >
105where
106 K : ::core::cmp::Eq + ::core::hash::Hash,
107{
108 fn preform( self ) -> Self::Preformed
110 {
111 self
112 }
113}
114
115#[ derive( Debug, Default ) ]
132pub struct HashSetDefinition< K, Context = (), Formed = HashSet< K >, End = ReturnStorage >
133where
134 K : ::core::cmp::Eq + ::core::hash::Hash,
135 End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >,
136{
137 _phantom : core::marker::PhantomData< ( K, Context, Formed, End ) >,
138}
139
140impl< K, Context, Formed, End > FormerDefinition
141for HashSetDefinition< K, Context, Formed, End >
142where
143 K : ::core::cmp::Eq + ::core::hash::Hash,
144 End : FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >,
145{
146 type Storage = HashSet< K >;
147 type Formed = Formed;
148 type Context = Context;
149
150 type Types = HashSetDefinitionTypes< K, Context, Formed >;
151 type End = End;
152}
153
154#[ derive( Debug, Default ) ]
164pub struct HashSetDefinitionTypes< K, Context = (), Formed = HashSet< K > >
165{
166 _phantom : core::marker::PhantomData< ( K, Context, Formed ) >,
167}
168
169impl< K, Context, Formed > FormerDefinitionTypes
170for HashSetDefinitionTypes< K, Context, Formed >
171where
172 K : ::core::cmp::Eq + ::core::hash::Hash,
173{
174 type Storage = HashSet< K >;
175 type Formed = Formed;
176 type Context = Context;
177}
178
179impl< K, Context, Formed > FormerMutator
182for HashSetDefinitionTypes< K, Context, Formed >
183where
184 K : ::core::cmp::Eq + ::core::hash::Hash,
185{
186}
187
188impl< K, Definition > EntityToFormer< Definition > for HashSet< K >
191where
192 K : ::core::cmp::Eq + ::core::hash::Hash,
193 Definition : FormerDefinition
194 <
195 Storage = HashSet< K >,
196 Types = HashSetDefinitionTypes
197 <
198 K,
199 < Definition as definition::FormerDefinition >::Context,
200 < Definition as definition::FormerDefinition >::Formed,
201 >,
202 >,
203 Definition::End : forming::FormingEnd< Definition::Types >,
204{
205 type Former = HashSetFormer< K, Definition::Context, Definition::Formed, Definition::End >;
206}
207
208impl< K > crate::EntityToStorage
209for HashSet< K >
210where
211 K : ::core::cmp::Eq + ::core::hash::Hash,
212{
213 type Storage = HashSet< K >;
214}
215
216impl< K, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End >
217for HashSet< K >
218where
219 K : ::core::cmp::Eq + ::core::hash::Hash,
220 End : crate::FormingEnd< HashSetDefinitionTypes< K, Context, Formed > >,
221{
222 type Definition = HashSetDefinition< K, Context, Formed, End >;
223 type Types = HashSetDefinitionTypes< K, Context, Formed >;
224}
225
226impl< K, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed >
227for HashSet< K >
228where
229 K : ::core::cmp::Eq + ::core::hash::Hash,
230{
231 type Types = HashSetDefinitionTypes< K, Context, Formed >;
232}
233
234pub type HashSetFormer< K, Context, Formed, End > =
244CollectionFormer::< K, HashSetDefinition< K, Context, Formed, End > >;
245
246pub trait HashSetExt< K > : sealed::Sealed
256where
257 K : ::core::cmp::Eq + ::core::hash::Hash,
258{
259 fn former() -> HashSetFormer< K, (), HashSet< K >, ReturnStorage >;
261}
262
263impl< K > HashSetExt< K > for HashSet< K >
264where
265 K : ::core::cmp::Eq + ::core::hash::Hash,
266{
267 fn former() -> HashSetFormer< K, (), HashSet< K >, ReturnStorage >
268 {
269 HashSetFormer::< K, (), HashSet< K >, ReturnStorage >::new( ReturnStorage::default() )
270 }
271}
272
273mod sealed
274{
275 use super::HashSet;
276 pub trait Sealed {}
277 impl< K > Sealed for HashSet< K > {}
278}