@@ -125,9 +125,8 @@ impl<K, V, S> Entries for IndexMap<K, V, S> {
125125
126126impl < K , V , S > fmt:: Debug for IndexMap < K , V , S >
127127where
128- K : fmt:: Debug + Hash + Eq ,
128+ K : fmt:: Debug ,
129129 V : fmt:: Debug ,
130- S : BuildHasher ,
131130{
132131 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
133132 if cfg ! ( not( feature = "test_debug" ) ) {
@@ -165,10 +164,7 @@ impl<K, V, S> IndexMap<K, V, S> {
165164 ///
166165 /// Computes in **O(n)** time.
167166 #[ inline]
168- pub fn with_capacity_and_hasher ( n : usize , hash_builder : S ) -> Self
169- where
170- S : BuildHasher ,
171- {
167+ pub fn with_capacity_and_hasher ( n : usize , hash_builder : S ) -> Self {
172168 if n == 0 {
173169 IndexMap {
174170 core : IndexMapCore :: new ( ) ,
@@ -182,6 +178,21 @@ impl<K, V, S> IndexMap<K, V, S> {
182178 }
183179 }
184180
181+ /// Create a new map with `hash_builder`
182+ pub fn with_hasher ( hash_builder : S ) -> Self {
183+ Self :: with_capacity_and_hasher ( 0 , hash_builder)
184+ }
185+
186+ /// Computes in **O(1)** time.
187+ pub fn capacity ( & self ) -> usize {
188+ self . core . capacity ( )
189+ }
190+
191+ /// Return a reference to the map's `BuildHasher`.
192+ pub fn hasher ( & self ) -> & S {
193+ & self . hash_builder
194+ }
195+
185196 /// Return the number of key-value pairs in the map.
186197 ///
187198 /// Computes in **O(1)** time.
@@ -198,40 +209,63 @@ impl<K, V, S> IndexMap<K, V, S> {
198209 self . len ( ) == 0
199210 }
200211
201- /// Create a new map with `hash_builder`
202- pub fn with_hasher ( hash_builder : S ) -> Self
203- where
204- S : BuildHasher ,
205- {
206- Self :: with_capacity_and_hasher ( 0 , hash_builder)
212+ /// Return an iterator over the key-value pairs of the map, in their order
213+ pub fn iter ( & self ) -> Iter < ' _ , K , V > {
214+ Iter {
215+ iter : self . as_entries ( ) . iter ( ) ,
216+ }
207217 }
208218
209- /// Return a reference to the map's `BuildHasher`.
210- pub fn hasher ( & self ) -> & S
211- where
212- S : BuildHasher ,
213- {
214- & self . hash_builder
219+ /// Return an iterator over the key-value pairs of the map, in their order
220+ pub fn iter_mut ( & mut self ) -> IterMut < ' _ , K , V > {
221+ IterMut {
222+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
223+ }
215224 }
216225
217- /// Computes in **O(1)** time.
218- pub fn capacity ( & self ) -> usize {
219- self . core . capacity ( )
226+ /// Return an iterator over the keys of the map, in their order
227+ pub fn keys ( & self ) -> Keys < ' _ , K , V > {
228+ Keys {
229+ iter : self . as_entries ( ) . iter ( ) ,
230+ }
231+ }
232+
233+ /// Return an iterator over the values of the map, in their order
234+ pub fn values ( & self ) -> Values < ' _ , K , V > {
235+ Values {
236+ iter : self . as_entries ( ) . iter ( ) ,
237+ }
238+ }
239+
240+ /// Return an iterator over mutable references to the the values of the map,
241+ /// in their order
242+ pub fn values_mut ( & mut self ) -> ValuesMut < ' _ , K , V > {
243+ ValuesMut {
244+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
245+ }
220246 }
221- }
222247
223- impl < K , V , S > IndexMap < K , V , S >
224- where
225- K : Hash + Eq ,
226- S : BuildHasher ,
227- {
228248 /// Remove all key-value pairs in the map, while preserving its capacity.
229249 ///
230250 /// Computes in **O(n)** time.
231251 pub fn clear ( & mut self ) {
232252 self . core . clear ( ) ;
233253 }
234254
255+ /// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
256+ /// Keeps the allocated memory for reuse.
257+ pub fn drain ( & mut self , range : RangeFull ) -> Drain < ' _ , K , V > {
258+ Drain {
259+ iter : self . core . drain ( range) ,
260+ }
261+ }
262+ }
263+
264+ impl < K , V , S > IndexMap < K , V , S >
265+ where
266+ K : Hash + Eq ,
267+ S : BuildHasher ,
268+ {
235269 /// Reserve capacity for `additional` more key-value pairs.
236270 ///
237271 /// Computes in **O(n)** time.
@@ -296,42 +330,6 @@ where
296330 self . core . entry ( hash, key)
297331 }
298332
299- /// Return an iterator over the key-value pairs of the map, in their order
300- pub fn iter ( & self ) -> Iter < ' _ , K , V > {
301- Iter {
302- iter : self . as_entries ( ) . iter ( ) ,
303- }
304- }
305-
306- /// Return an iterator over the key-value pairs of the map, in their order
307- pub fn iter_mut ( & mut self ) -> IterMut < ' _ , K , V > {
308- IterMut {
309- iter : self . as_entries_mut ( ) . iter_mut ( ) ,
310- }
311- }
312-
313- /// Return an iterator over the keys of the map, in their order
314- pub fn keys ( & self ) -> Keys < ' _ , K , V > {
315- Keys {
316- iter : self . as_entries ( ) . iter ( ) ,
317- }
318- }
319-
320- /// Return an iterator over the values of the map, in their order
321- pub fn values ( & self ) -> Values < ' _ , K , V > {
322- Values {
323- iter : self . as_entries ( ) . iter ( ) ,
324- }
325- }
326-
327- /// Return an iterator over mutable references to the the values of the map,
328- /// in their order
329- pub fn values_mut ( & mut self ) -> ValuesMut < ' _ , K , V > {
330- ValuesMut {
331- iter : self . as_entries_mut ( ) . iter_mut ( ) ,
332- }
333- }
334-
335333 /// Return `true` if an equivalent to `key` exists in the map.
336334 ///
337335 /// Computes in **O(1)** time (average).
@@ -660,14 +658,6 @@ where
660658 pub fn reverse ( & mut self ) {
661659 self . core . reverse ( )
662660 }
663-
664- /// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
665- /// Keeps the allocated memory for reuse.
666- pub fn drain ( & mut self , range : RangeFull ) -> Drain < ' _ , K , V > {
667- Drain {
668- iter : self . core . drain ( range) ,
669- }
670- }
671661}
672662
673663impl < K , V , S > IndexMap < K , V , S > {
@@ -963,35 +953,23 @@ impl<K, V> DoubleEndedIterator for Drain<'_, K, V> {
963953 double_ended_iterator_methods ! ( Bucket :: key_value) ;
964954}
965955
966- impl < ' a , K , V , S > IntoIterator for & ' a IndexMap < K , V , S >
967- where
968- K : Hash + Eq ,
969- S : BuildHasher ,
970- {
956+ impl < ' a , K , V , S > IntoIterator for & ' a IndexMap < K , V , S > {
971957 type Item = ( & ' a K , & ' a V ) ;
972958 type IntoIter = Iter < ' a , K , V > ;
973959 fn into_iter ( self ) -> Self :: IntoIter {
974960 self . iter ( )
975961 }
976962}
977963
978- impl < ' a , K , V , S > IntoIterator for & ' a mut IndexMap < K , V , S >
979- where
980- K : Hash + Eq ,
981- S : BuildHasher ,
982- {
964+ impl < ' a , K , V , S > IntoIterator for & ' a mut IndexMap < K , V , S > {
983965 type Item = ( & ' a K , & ' a mut V ) ;
984966 type IntoIter = IterMut < ' a , K , V > ;
985967 fn into_iter ( self ) -> Self :: IntoIter {
986968 self . iter_mut ( )
987969 }
988970}
989971
990- impl < K , V , S > IntoIterator for IndexMap < K , V , S >
991- where
992- K : Hash + Eq ,
993- S : BuildHasher ,
994- {
972+ impl < K , V , S > IntoIterator for IndexMap < K , V , S > {
995973 type Item = ( K , V ) ;
996974 type IntoIter = IntoIter < K , V > ;
997975 fn into_iter ( self ) -> Self :: IntoIter {
@@ -1099,7 +1077,7 @@ where
10991077
11001078impl < K , V , S > Default for IndexMap < K , V , S >
11011079where
1102- S : BuildHasher + Default ,
1080+ S : Default ,
11031081{
11041082 /// Return an empty `IndexMap`
11051083 fn default ( ) -> Self {
0 commit comments