@@ -17,8 +17,8 @@ use btree_map::{BTreeMap, Keys, MoveEntries};
17
17
use std:: hash:: Hash ;
18
18
use core:: borrow:: BorrowFrom ;
19
19
use core:: default:: Default ;
20
- use core:: { iter , fmt} ;
21
- use core:: iter:: Peekable ;
20
+ use core:: fmt;
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 > {
@@ -105,7 +108,7 @@ impl<T> BTreeSet<T> {
105
108
/// ```
106
109
#[ unstable = "matches collection reform specification, waiting for dust to settle" ]
107
110
pub fn iter < ' a > ( & ' a self ) -> Items < ' a , T > {
108
- self . map . keys ( )
111
+ Items { iter : self . map . keys ( ) }
109
112
}
110
113
111
114
/// Gets an iterator for moving out the BtreeSet's contents.
@@ -124,7 +127,7 @@ impl<T> BTreeSet<T> {
124
127
pub fn into_iter ( self ) -> MoveItems < T > {
125
128
fn first < A , B > ( ( a, _) : ( A , B ) ) -> A { a }
126
129
127
- self . map . into_iter ( ) . map ( first)
130
+ MoveItems { iter : self . map . into_iter ( ) . map ( first) }
128
131
}
129
132
}
130
133
@@ -635,6 +638,25 @@ impl<T: Show> Show for BTreeSet<T> {
635
638
}
636
639
}
637
640
641
+ impl < ' a , T > Iterator < & ' a T > for Items < ' a , T > {
642
+ fn next ( & mut self ) -> Option < & ' a T > { self . iter . next ( ) }
643
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . iter . size_hint ( ) }
644
+ }
645
+ impl < ' a , T > DoubleEndedIterator < & ' a T > for Items < ' a , T > {
646
+ fn next_back ( & mut self ) -> Option < & ' a T > { self . iter . next_back ( ) }
647
+ }
648
+ impl < ' a , T > ExactSizeIterator < & ' a T > for Items < ' a , T > { }
649
+
650
+
651
+ impl < T > Iterator < T > for MoveItems < T > {
652
+ fn next ( & mut self ) -> Option < T > { self . iter . next ( ) }
653
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . iter . size_hint ( ) }
654
+ }
655
+ impl < T > DoubleEndedIterator < T > for MoveItems < T > {
656
+ fn next_back ( & mut self ) -> Option < T > { self . iter . next_back ( ) }
657
+ }
658
+ impl < T > ExactSizeIterator < T > for MoveItems < T > { }
659
+
638
660
/// Compare `x` and `y`, but return `short` if x is None and `long` if y is None
639
661
fn cmp_opt < T : Ord > ( x : Option < & T > , y : Option < & T > ,
640
662
short : Ordering , long : Ordering ) -> Ordering {
0 commit comments