@@ -19,7 +19,7 @@ use fmt;
19
19
use hash:: { Hash , Hasher , RandomSipHasher } ;
20
20
use iter:: { Iterator , IteratorExt , FromIterator , FilterMap , Chain , Repeat , Zip , Extend , repeat} ;
21
21
use iter;
22
- use option:: Option :: { Some , None } ;
22
+ use option:: Option :: { Some , None , mod } ;
23
23
use result:: Result :: { Ok , Err } ;
24
24
25
25
use super :: map:: { HashMap , Entries , MoveEntries , INITIAL_CAPACITY } ;
@@ -306,10 +306,13 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
306
306
/// ```
307
307
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
308
308
pub fn difference < ' a > ( & ' a self , other : & ' a HashSet < T , H > ) -> SetAlgebraItems < ' a , T , H > {
309
- repeat ( other) . zip ( self . iter ( ) )
310
- . filter_map ( |( other, elt) | {
311
- if !other. contains ( elt) { Some ( elt) } else { None }
312
- } )
309
+ fn filter < ' a , T , S , H > ( ( other, elt) : ( & HashSet < T , H > , & ' a T ) ) -> Option < & ' a T > where
310
+ T : Eq + Hash < S > , H : Hasher < S >
311
+ {
312
+ if !other. contains ( elt) { Some ( elt) } else { None }
313
+ }
314
+
315
+ repeat ( other) . zip ( self . iter ( ) ) . filter_map ( filter)
313
316
}
314
317
315
318
/// Visit the values representing the symmetric difference.
@@ -356,12 +359,14 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
356
359
/// assert_eq!(diff, [2i, 3].iter().map(|&x| x).collect());
357
360
/// ```
358
361
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
359
- pub fn intersection < ' a > ( & ' a self , other : & ' a HashSet < T , H > )
360
- -> SetAlgebraItems < ' a , T , H > {
361
- repeat ( other) . zip ( self . iter ( ) )
362
- . filter_map ( |( other, elt) | {
363
- if other. contains ( elt) { Some ( elt) } else { None }
364
- } )
362
+ pub fn intersection < ' a > ( & ' a self , other : & ' a HashSet < T , H > ) -> SetAlgebraItems < ' a , T , H > {
363
+ fn filter < ' a , T , S , H > ( ( other, elt) : ( & HashSet < T , H > , & ' a T ) ) -> Option < & ' a T > where
364
+ T : Eq + Hash < S > , H : Hasher < S >
365
+ {
366
+ if other. contains ( elt) { Some ( elt) } else { None }
367
+ }
368
+
369
+ repeat ( other) . zip ( self . iter ( ) ) . filter_map ( filter)
365
370
}
366
371
367
372
/// Visit the values representing the union.
@@ -621,9 +626,12 @@ pub type SetMoveItems<K> = iter::Map<(K, ()), K, MoveEntries<K, ()>, fn((K, ()))
621
626
// `Repeat` is used to feed the filter closure an explicit capture
622
627
// of a reference to the other set
623
628
/// Set operations iterator
624
- pub type SetAlgebraItems < ' a , T , H > =
625
- FilterMap < ' static , ( & ' a HashSet < T , H > , & ' a T ) , & ' a T ,
626
- Zip < Repeat < & ' a HashSet < T , H > > , SetItems < ' a , T > > > ;
629
+ pub type SetAlgebraItems < ' a , T , H > = FilterMap <
630
+ ( & ' a HashSet < T , H > , & ' a T ) ,
631
+ & ' a T ,
632
+ Zip < Repeat < & ' a HashSet < T , H > > , SetItems < ' a , T > > ,
633
+ for <' b > fn ( ( & HashSet < T , H > , & ' b T ) ) -> Option < & ' b T > ,
634
+ > ;
627
635
628
636
#[ cfg( test) ]
629
637
mod test_set {
0 commit comments