@@ -298,12 +298,23 @@ pub enum IMapIter<'a, K, V> {
298298impl < ' a , K : Eq + Hash + ImplicitClone + ' static , V : PartialEq + ImplicitClone + ' static > Iterator
299299 for IMapIter < ' a , K , V >
300300{
301- type Item = ( K , V ) ;
301+ type Item = ( & ' a K , & ' a V ) ;
302302
303303 fn next ( & mut self ) -> Option < Self :: Item > {
304304 match self {
305- Self :: Slice ( it) => it. next ( ) . map ( |( k, v) | ( k. clone ( ) , v. clone ( ) ) ) ,
306- Self :: Map ( it) => it. next ( ) . map ( |( k, v) | ( k. clone ( ) , v. clone ( ) ) ) ,
305+ Self :: Slice ( it) => it. next ( ) . map ( |( k, v) | ( k, v) ) ,
306+ Self :: Map ( it) => it. next ( ) ,
307+ }
308+ }
309+ }
310+
311+ impl < ' a , K : Eq + Hash + ImplicitClone + ' static , V : PartialEq + ImplicitClone + ' static >
312+ DoubleEndedIterator for IMapIter < ' a , K , V >
313+ {
314+ fn next_back ( & mut self ) -> Option < Self :: Item > {
315+ match self {
316+ Self :: Slice ( it) => it. next_back ( ) . map ( |( k, v) | ( k, v) ) ,
317+ Self :: Map ( it) => it. next_back ( ) ,
307318 }
308319 }
309320}
@@ -317,12 +328,23 @@ pub enum IMapKeys<'a, K, V> {
317328impl < ' a , K : Eq + Hash + ImplicitClone + ' static , V : PartialEq + ImplicitClone + ' static > Iterator
318329 for IMapKeys < ' a , K , V >
319330{
320- type Item = K ;
331+ type Item = & ' a K ;
321332
322333 fn next ( & mut self ) -> Option < Self :: Item > {
323334 match self {
324- Self :: Slice ( it) => it. next ( ) . map ( |( k, _) | k. clone ( ) ) ,
325- Self :: Map ( it) => it. next ( ) . cloned ( ) ,
335+ Self :: Slice ( it) => it. next ( ) . map ( |( k, _) | k) ,
336+ Self :: Map ( it) => it. next ( ) ,
337+ }
338+ }
339+ }
340+
341+ impl < ' a , K : Eq + Hash + ImplicitClone + ' static , V : PartialEq + ImplicitClone + ' static >
342+ DoubleEndedIterator for IMapKeys < ' a , K , V >
343+ {
344+ fn next_back ( & mut self ) -> Option < Self :: Item > {
345+ match self {
346+ Self :: Slice ( it) => it. next_back ( ) . map ( |( k, _) | k) ,
347+ Self :: Map ( it) => it. next_back ( ) ,
326348 }
327349 }
328350}
@@ -336,12 +358,23 @@ pub enum IMapValues<'a, K, V> {
336358impl < ' a , K : Eq + Hash + ImplicitClone + ' static , V : PartialEq + ImplicitClone + ' static > Iterator
337359 for IMapValues < ' a , K , V >
338360{
339- type Item = V ;
361+ type Item = & ' a V ;
340362
341363 fn next ( & mut self ) -> Option < Self :: Item > {
342364 match self {
343- Self :: Slice ( it) => it. next ( ) . map ( |( _, v) | v. clone ( ) ) ,
344- Self :: Map ( it) => it. next ( ) . cloned ( ) ,
365+ Self :: Slice ( it) => it. next ( ) . map ( |( _, v) | v) ,
366+ Self :: Map ( it) => it. next ( ) ,
367+ }
368+ }
369+ }
370+
371+ impl < ' a , K : Eq + Hash + ImplicitClone + ' static , V : PartialEq + ImplicitClone + ' static >
372+ DoubleEndedIterator for IMapValues < ' a , K , V >
373+ {
374+ fn next_back ( & mut self ) -> Option < Self :: Item > {
375+ match self {
376+ Self :: Slice ( it) => it. next_back ( ) . map ( |( _, v) | v) ,
377+ Self :: Map ( it) => it. next_back ( ) ,
345378 }
346379 }
347380}
@@ -413,12 +446,12 @@ mod test_map {
413446 assert_eq ! (
414447 flattened_vec,
415448 [
416- ( IString :: from( "foo1" ) , 1 ) ,
417- ( IString :: from( "bar1" ) , 2 ) ,
418- ( IString :: from( "baz1" ) , 3 ) ,
419- ( IString :: from( "foo2" ) , 4 ) ,
420- ( IString :: from( "bar2" ) , 5 ) ,
421- ( IString :: from( "baz2" ) , 6 ) ,
449+ ( & IString :: from( "foo1" ) , & 1 ) ,
450+ ( & IString :: from( "bar1" ) , & 2 ) ,
451+ ( & IString :: from( "baz1" ) , & 3 ) ,
452+ ( & IString :: from( "foo2" ) , & 4 ) ,
453+ ( & IString :: from( "bar2" ) , & 5 ) ,
454+ ( & IString :: from( "baz2" ) , & 6 ) ,
422455 ]
423456 ) ;
424457 }
0 commit comments