1use crate::*;
9use collection_tools::HashMap;
10
11impl< K, V > Collection for HashMap< K, V >
12where
13 K : core::cmp::Eq + core::hash::Hash,
14{
15 type Entry = ( K, V );
16 type Val = V;
17
18 #[ inline( always ) ]
19 fn entry_to_val( e : Self::Entry ) -> Self::Val
20 {
21 e.1
22 }
23
24}
25
26impl< K, V > CollectionAdd for HashMap< K, V >
27where
28 K : core::cmp::Eq + core::hash::Hash,
29{
30
31 #[ inline( always ) ]
32 fn add( &mut self, ( k, v ) : Self::Entry ) -> bool
33 {
34 self.insert( k, v ).map_or_else( || true, | _ | false )
35 }
36
37}
38
39impl< K, V > CollectionAssign for HashMap< K, V >
40where
41 K : core::cmp::Eq + core::hash::Hash,
42{
43
44 fn assign< Elements >( &mut self, elements : Elements ) -> usize
45 where
46 Elements : IntoIterator< Item = Self::Entry >
47 {
48 let initial_len = self.len();
49 self.extend( elements );
50 self.len() - initial_len
51 }
52}
53
54impl< K, E > Storage
57for HashMap< K, E >
58where
59 K : ::core::cmp::Eq + ::core::hash::Hash,
60{
61 type Preformed = HashMap< K, E >;
62}
63
64impl< K, E > StoragePreform
65for HashMap< K, E >
66where
67 K : ::core::cmp::Eq + ::core::hash::Hash,
68{
69 fn preform( self ) -> Self::Preformed
70 {
71 self
72 }
73}
74
75#[ derive( Debug, Default ) ]
93pub struct HashMapDefinition< K, E, Context = (), Formed = HashMap< K, E >, End = ReturnStorage >
94where
95 K : ::core::cmp::Eq + ::core::hash::Hash,
96 End : FormingEnd< HashMapDefinitionTypes< K, E, Context, Formed > >,
97{
98 _phantom : core::marker::PhantomData< ( K, E, Context, Formed, End ) >,
99}
100
101impl< K, E, Context, Formed, End > FormerDefinition
102for HashMapDefinition< K, E, Context, Formed, End >
103where
104 K : ::core::cmp::Eq + ::core::hash::Hash,
105 End : FormingEnd< HashMapDefinitionTypes< K, E, Context, Formed > >,
106{
107
108 type Storage = HashMap< K, E >;
109 type Formed = Formed;
110 type Context = Context;
111
112 type Types = HashMapDefinitionTypes< K, E, Context, Formed >;
113 type End = End;
114
115}
116
117#[ derive( Debug, Default ) ]
132pub struct HashMapDefinitionTypes< K, E, Context = (), Formed = HashMap< K, E > >
133{
134 _phantom : core::marker::PhantomData< ( K, E, Context, Formed ) >,
135}
136
137impl< K, E, Context, Formed > FormerDefinitionTypes
138for HashMapDefinitionTypes< K, E, Context, Formed >
139where
140 K : ::core::cmp::Eq + ::core::hash::Hash,
141{
142 type Storage = HashMap< K, E >;
143 type Formed = Formed;
144 type Context = Context;
145}
146
147impl< K, E, Context, Formed > FormerMutator
150for HashMapDefinitionTypes< K, E, Context, Formed >
151where
152 K : ::core::cmp::Eq + ::core::hash::Hash,
153{
154}
155
156impl< K, E, Definition > EntityToFormer< Definition > for HashMap< K, E >
159where
160 K : ::core::cmp::Eq + ::core::hash::Hash,
161 Definition : FormerDefinition
162 <
163 Storage = HashMap< K, E >,
164 Types = HashMapDefinitionTypes
165 <
166 K,
167 E,
168 < Definition as definition::FormerDefinition >::Context,
169 < Definition as definition::FormerDefinition >::Formed,
170 >,
171 >,
172 Definition::End : forming::FormingEnd< Definition::Types >,
173{
174 type Former = HashMapFormer< K, E, Definition::Context, Definition::Formed, Definition::End >;
175}
176
177impl< K, E > crate::EntityToStorage
178for HashMap< K, E >
179where
180 K : ::core::cmp::Eq + ::core::hash::Hash,
181{
182 type Storage = HashMap< K, E >;
183}
184
185impl< K, E, Context, Formed, End > crate::EntityToDefinition< Context, Formed, End >
186for HashMap< K, E >
187where
188 K : ::core::cmp::Eq + ::core::hash::Hash,
189 End : crate::FormingEnd< HashMapDefinitionTypes< K, E, Context, Formed > >,
190{
191 type Definition = HashMapDefinition< K, E, Context, Formed, End >;
192 type Types = HashMapDefinitionTypes< K, E, Context, Formed >;
193}
194
195impl< K, E, Context, Formed > crate::EntityToDefinitionTypes< Context, Formed >
196for HashMap< K, E >
197where
198 K : ::core::cmp::Eq + ::core::hash::Hash,
199{
200 type Types = HashMapDefinitionTypes< K, E, Context, Formed >;
201}
202
203pub type HashMapFormer< K, E, Context, Formed, End > =
217CollectionFormer::< ( K, E ), HashMapDefinition< K, E, Context, Formed, End > >;
218
219pub trait HashMapExt< K, E > : sealed::Sealed
230where
231 K : ::core::cmp::Eq + ::core::hash::Hash,
232{
233 fn former() -> HashMapFormer< K, E, (), HashMap< K, E >, ReturnStorage >;
235}
236
237impl< K, E > HashMapExt< K, E > for HashMap< K, E >
238where
239 K : ::core::cmp::Eq + ::core::hash::Hash,
240{
241 fn former() -> HashMapFormer< K, E, (), HashMap< K, E >, ReturnStorage >
242 {
243 HashMapFormer::< K, E, (), HashMap< K, E >, ReturnStorage >::new( ReturnStorage::default() )
244 }
245}
246
247mod sealed
248{
249 use super::HashMap;
250 pub trait Sealed {}
251 impl< K, E > Sealed for HashMap< K, E > {}
252}