@@ -358,3 +358,43 @@ impl Extend<()> for () {
358358 }
359359 fn extend_one ( & mut self , _item : ( ) ) { }
360360}
361+
362+ #[ stable( feature = "extend_for_tuple" , since = "1.54.0" ) ]
363+ impl < A , B , ExtendA , ExtendB > Extend < ( A , B ) > for ( ExtendA , ExtendB )
364+ where
365+ ExtendA : Extend < A > ,
366+ ExtendB : Extend < B > ,
367+ {
368+ fn extend < T : IntoIterator < Item = ( A , B ) > > ( & mut self , into_iter : T ) {
369+ let ( a, b) = self ;
370+ let iter = into_iter. into_iter ( ) ;
371+
372+ fn extend < ' a , A , B > (
373+ a : & ' a mut impl Extend < A > ,
374+ b : & ' a mut impl Extend < B > ,
375+ ) -> impl FnMut ( ( ) , ( A , B ) ) + ' a {
376+ move |( ) , ( t, u) | {
377+ a. extend_one ( t) ;
378+ b. extend_one ( u) ;
379+ }
380+ }
381+
382+ let ( lower_bound, _) = iter. size_hint ( ) ;
383+ if lower_bound > 0 {
384+ a. extend_reserve ( lower_bound) ;
385+ b. extend_reserve ( lower_bound) ;
386+ }
387+
388+ iter. fold ( ( ) , extend ( a, b) ) ;
389+ }
390+
391+ fn extend_one ( & mut self , item : ( A , B ) ) {
392+ self . 0 . extend_one ( item. 0 ) ;
393+ self . 1 . extend_one ( item. 1 ) ;
394+ }
395+
396+ fn extend_reserve ( & mut self , additional : usize ) {
397+ self . 0 . extend_reserve ( additional) ;
398+ self . 1 . extend_reserve ( additional) ;
399+ }
400+ }
0 commit comments