@@ -26,6 +26,7 @@ use std::hash::{Writer, Hash};
26
26
use core:: default:: Default ;
27
27
use core:: { iter, fmt, mem} ;
28
28
use core:: fmt:: Show ;
29
+ use core:: iter:: Map ;
29
30
30
31
use ring_buf:: RingBuf ;
31
32
@@ -107,12 +108,14 @@ pub struct MoveEntries<K, V> {
107
108
}
108
109
109
110
/// An iterator over a BTreeMap's keys.
110
- pub type Keys < ' a , K , V > =
111
- iter:: Map < ( & ' a K , & ' a V ) , & ' a K , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a K > ;
111
+ pub struct Keys < ' a , K : ' a , V : ' a > {
112
+ inner : Map < ( & ' a K , & ' a V ) , & ' a K , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a K >
113
+ }
112
114
113
115
/// An iterator over a BTreeMap's values.
114
- pub type Values < ' a , K , V > =
115
- iter:: Map < ( & ' a K , & ' a V ) , & ' a V , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a V > ;
116
+ pub struct Values < ' a , K : ' a , V : ' a > {
117
+ inner : Map < ( & ' a K , & ' a V ) , & ' a V , Entries < ' a , K , V > , fn ( ( & ' a K , & ' a V ) ) -> & ' a V >
118
+ }
116
119
117
120
/// A view into a single entry in a map, which may either be vacant or occupied.
118
121
pub enum Entry < ' a , K : ' a , V : ' a > {
@@ -1061,6 +1064,25 @@ impl<K, V> DoubleEndedIterator<(K, V)> for MoveEntries<K, V> {
1061
1064
impl < K , V > ExactSizeIterator < ( K , V ) > for MoveEntries < K , V > { }
1062
1065
1063
1066
1067
+ impl < ' a , K , V > Iterator < & ' a K > for Keys < ' a , K , V > {
1068
+ fn next ( & mut self ) -> Option < ( & ' a K ) > { self . inner . next ( ) }
1069
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
1070
+ }
1071
+ impl < ' a , K , V > DoubleEndedIterator < & ' a K > for Keys < ' a , K , V > {
1072
+ fn next_back ( & mut self ) -> Option < ( & ' a K ) > { self . inner . next_back ( ) }
1073
+ }
1074
+ impl < ' a , K , V > ExactSizeIterator < & ' a K > for Keys < ' a , K , V > { }
1075
+
1076
+
1077
+ impl < ' a , K , V > Iterator < & ' a V > for Values < ' a , K , V > {
1078
+ fn next ( & mut self ) -> Option < ( & ' a V ) > { self . inner . next ( ) }
1079
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
1080
+ }
1081
+ impl < ' a , K , V > DoubleEndedIterator < & ' a V > for Values < ' a , K , V > {
1082
+ fn next_back ( & mut self ) -> Option < ( & ' a V ) > { self . inner . next_back ( ) }
1083
+ }
1084
+ impl < ' a , K , V > ExactSizeIterator < & ' a V > for Values < ' a , K , V > { }
1085
+
1064
1086
1065
1087
impl < ' a , K : Ord , V > VacantEntry < ' a , K , V > {
1066
1088
/// Sets the value of the entry with the VacantEntry's key,
@@ -1211,7 +1233,7 @@ impl<K, V> BTreeMap<K, V> {
1211
1233
pub fn keys < ' a > ( & ' a self ) -> Keys < ' a , K , V > {
1212
1234
fn first < A , B > ( ( a, _) : ( A , B ) ) -> A { a }
1213
1235
1214
- self . iter ( ) . map ( first)
1236
+ Keys { inner : self . iter ( ) . map ( first) }
1215
1237
}
1216
1238
1217
1239
/// Gets an iterator over the values of the map.
@@ -1232,7 +1254,7 @@ impl<K, V> BTreeMap<K, V> {
1232
1254
pub fn values < ' a > ( & ' a self ) -> Values < ' a , K , V > {
1233
1255
fn second < A , B > ( ( _, b) : ( A , B ) ) -> B { b }
1234
1256
1235
- self . iter ( ) . map ( second)
1257
+ Values { inner : self . iter ( ) . map ( second) }
1236
1258
}
1237
1259
1238
1260
/// Return the number of elements in the map.
0 commit comments