@@ -306,7 +306,6 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
306306 key : & ' b Q ,
307307 ) -> CommonPrefixesIter < ' a , ' b , K :: Borrowed , V >
308308 where
309- ' a : ' b ,
310309 Q : ?Sized + AsRef < K :: Borrowed > ,
311310 {
312311 CommonPrefixesIter {
@@ -333,10 +332,13 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
333332 /// .flatten()
334333 /// .eq(vec![&"a", &"b", &"c", &"d"].into_iter()));
335334 /// ```
336- pub fn common_prefix_values < ' a , ' b , Q > ( & ' a self , key : & ' b Q ) -> impl ' a + Iterator < Item = & ' a V >
335+ pub fn common_prefix_values < ' a , ' b , Q > (
336+ & ' a self ,
337+ key : & ' b Q ,
338+ ) -> impl Iterator < Item = & ' a V > + use < ' a , ' b , Q , K , V >
337339 where
338- ' b : ' a ,
339340 Q : ?Sized + AsRef < K :: Borrowed > ,
341+ <K as Bytes >:: Borrowed : ' b ,
340342 {
341343 self . tree
342344 . common_prefixes ( key. as_ref ( ) )
@@ -479,10 +481,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
479481 pub fn iter_prefix < ' a , ' b > (
480482 & ' a self ,
481483 prefix : & ' b K :: Borrowed ,
482- ) -> impl ' a + Iterator < Item = ( K , & ' a V ) >
483- where
484- ' b : ' a ,
485- {
484+ ) -> impl Iterator < Item = ( K , & ' a V ) > + use < ' a , ' b , K , V > {
486485 self . tree
487486 . iter_prefix ( prefix)
488487 . into_iter ( )
@@ -506,10 +505,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
506505 pub fn iter_prefix_mut < ' a , ' b > (
507506 & ' a mut self ,
508507 prefix : & ' b K :: Borrowed ,
509- ) -> impl ' a + Iterator < Item = ( K , & ' a mut V ) >
510- where
511- ' b : ' a ,
512- {
508+ ) -> impl Iterator < Item = ( K , & ' a mut V ) > + use < ' a , ' b , K , V > {
513509 self . tree
514510 . iter_prefix_mut ( prefix)
515511 . into_iter ( )
@@ -987,4 +983,44 @@ mod tests {
987983 assert_eq ! ( map. get( "インターポール" ) , Some ( & 1 ) ) ;
988984 assert_eq ! ( map. get( "インターポル" ) , Some ( & 2 ) ) ;
989985 }
986+
987+ #[ test]
988+ fn issue42_iter_prefix ( ) {
989+ let mut map = StringPatriciaMap :: new ( ) ;
990+ map. insert ( "a0/b0" , 0 ) ;
991+ map. insert ( "a1/b1" , 0 ) ;
992+ let items: Vec < _ > = {
993+ let prefix = "a0" . to_owned ( ) ;
994+ map. iter_prefix ( & prefix) . collect ( )
995+ } ;
996+
997+ assert_eq ! ( items, vec![ ( "a0/b0" . to_owned( ) , & 0 ) ] )
998+ }
999+
1000+ #[ test]
1001+ #[ ignore = "bug causing assertion failure" ]
1002+ fn issue42_iter_prefix_mut ( ) {
1003+ let mut map = StringPatriciaMap :: new ( ) ;
1004+ map. insert ( "a0/b0" , 0 ) ;
1005+ map. insert ( "a1/b1" , 0 ) ;
1006+ let items: Vec < _ > = {
1007+ let prefix = "a0" . to_owned ( ) ;
1008+ map. iter_prefix_mut ( & prefix) . collect ( )
1009+ } ;
1010+
1011+ assert_eq ! ( items, vec![ ( "a0/b0" . to_owned( ) , & mut 0 ) ] )
1012+ }
1013+
1014+ #[ test]
1015+ fn issue42_common_prefix_values ( ) {
1016+ let mut map = StringPatriciaMap :: new ( ) ;
1017+ map. insert ( "a0/b0" , 0 ) ;
1018+ map. insert ( "a1/b1" , 0 ) ;
1019+ let items: Vec < _ > = {
1020+ let prefix = "a0/b0/c0" . to_owned ( ) ;
1021+ map. common_prefix_values ( & prefix) . collect ( )
1022+ } ;
1023+
1024+ assert_eq ! ( items, vec![ & 0 ] )
1025+ }
9901026}
0 commit comments