File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -828,6 +828,13 @@ impl<V> Extend<(usize, V)> for VecMap<V> {
828
828
}
829
829
}
830
830
831
+ #[ unstable( feature = "extend_ref" , reason = "recently added" ) ]
832
+ impl < ' a , V : Copy > Extend < ( usize , & ' a V ) > for VecMap < V > {
833
+ fn extend < I : IntoIterator < Item =( usize , & ' a V ) > > ( & mut self , iter : I ) {
834
+ self . extend ( iter. into_iter ( ) . map ( |( key, & value) | ( key, value) ) ) ;
835
+ }
836
+ }
837
+
831
838
impl < V > Index < usize > for VecMap < V > {
832
839
type Output = V ;
833
840
Original file line number Diff line number Diff line change @@ -493,6 +493,22 @@ fn test_entry(){
493
493
assert_eq ! ( map. len( ) , 6 ) ;
494
494
}
495
495
496
+ #[ test]
497
+ fn test_extend_ref ( ) {
498
+ let mut a = VecMap :: new ( ) ;
499
+ a. insert ( 1 , "one" ) ;
500
+ let mut b = VecMap :: new ( ) ;
501
+ b. insert ( 2 , "two" ) ;
502
+ b. insert ( 3 , "three" ) ;
503
+
504
+ a. extend ( & b) ;
505
+
506
+ assert_eq ! ( a. len( ) , 3 ) ;
507
+ assert_eq ! ( a[ & 1 ] , "one" ) ;
508
+ assert_eq ! ( a[ & 2 ] , "two" ) ;
509
+ assert_eq ! ( a[ & 3 ] , "three" ) ;
510
+ }
511
+
496
512
mod bench {
497
513
use std:: collections:: VecMap ;
498
514
You can’t perform that action at this time.
0 commit comments