@@ -18,7 +18,7 @@ use std::hash::Hash;
18
18
use core:: borrow:: BorrowFrom ;
19
19
use core:: default:: Default ;
20
20
use core:: { iter, fmt} ;
21
- use core:: iter:: Peekable ;
21
+ use core:: iter:: { Peekable , Map } ;
22
22
use core:: fmt:: Show ;
23
23
24
24
// FIXME(conventions): implement bounded iterators
@@ -33,11 +33,14 @@ pub struct BTreeSet<T>{
33
33
}
34
34
35
35
/// An iterator over a BTreeSet's items.
36
- pub type Items < ' a , T > = Keys < ' a , T , ( ) > ;
36
+ pub struct Items < ' a , T : ' a > {
37
+ iter : Keys < ' a , T , ( ) >
38
+ }
37
39
38
40
/// An owning iterator over a BTreeSet's items.
39
- pub type MoveItems < T > =
40
- iter:: Map < ( T , ( ) ) , T , MoveEntries < T , ( ) > , fn ( ( T , ( ) ) ) -> T > ;
41
+ pub struct MoveItems < T > {
42
+ iter : Map < ( T , ( ) ) , T , MoveEntries < T , ( ) > , fn ( ( T , ( ) ) ) -> T >
43
+ }
41
44
42
45
/// A lazy iterator producing elements in the set difference (in-order).
43
46
pub struct DifferenceItems < ' a , T : ' a > {
@@ -82,15 +85,15 @@ impl<T> BTreeSet<T> {
82
85
/// Gets an iterator over the BTreeSet's contents.
83
86
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
84
87
pub fn iter < ' a > ( & ' a self ) -> Items < ' a , T > {
85
- self . map . keys ( )
88
+ Items { iter : self . map . keys ( ) }
86
89
}
87
90
88
91
/// Gets an iterator for moving out the BtreeSet's contents.
89
92
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
90
93
pub fn into_iter ( self ) -> MoveItems < T > {
91
94
fn first < A , B > ( ( a, _) : ( A , B ) ) -> A { a }
92
95
93
- self . map . into_iter ( ) . map ( first)
96
+ MoveItems { iter : self . map . into_iter ( ) . map ( first) }
94
97
}
95
98
}
96
99
@@ -505,6 +508,25 @@ impl<T: Show> Show for BTreeSet<T> {
505
508
}
506
509
}
507
510
511
+ impl < ' a , T > Iterator < & ' a T > for Items < ' a , T > {
512
+ fn next ( & mut self ) -> Option < & ' a T > { self . iter . next ( ) }
513
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . iter . size_hint ( ) }
514
+ }
515
+ impl < ' a , T > DoubleEndedIterator < & ' a T > for Items < ' a , T > {
516
+ fn next_back ( & mut self ) -> Option < & ' a T > { self . iter . next_back ( ) }
517
+ }
518
+ impl < ' a , T > ExactSizeIterator < & ' a T > for Items < ' a , T > { }
519
+
520
+
521
+ impl < T > Iterator < T > for MoveItems < T > {
522
+ fn next ( & mut self ) -> Option < T > { self . iter . next ( ) }
523
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . iter . size_hint ( ) }
524
+ }
525
+ impl < T > DoubleEndedIterator < T > for MoveItems < T > {
526
+ fn next_back ( & mut self ) -> Option < T > { self . iter . next_back ( ) }
527
+ }
528
+ impl < T > ExactSizeIterator < T > for MoveItems < T > { }
529
+
508
530
/// Compare `x` and `y`, but return `short` if x is None and `long` if y is None
509
531
fn cmp_opt < T : Ord > ( x : Option < & T > , y : Option < & T > ,
510
532
short : Ordering , long : Ordering ) -> Ordering {
0 commit comments