@@ -1045,6 +1045,11 @@ impl<A, B> Iterator for Zip<A, B> where A: Iterator, B: Iterator
10451045 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
10461046 ZipImpl :: size_hint ( self )
10471047 }
1048+
1049+ #[ inline]
1050+ fn nth ( & mut self , n : usize ) -> Option < Self :: Item > {
1051+ ZipImpl :: nth ( self , n)
1052+ }
10481053}
10491054
10501055#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1065,6 +1070,14 @@ trait ZipImpl<A, B> {
10651070 fn new ( a : A , b : B ) -> Self ;
10661071 fn next ( & mut self ) -> Option < Self :: Item > ;
10671072 fn size_hint ( & self ) -> ( usize , Option < usize > ) ;
1073+ fn nth ( & mut self , n : usize ) -> Option < Self :: Item > ;
1074+ fn super_nth ( & mut self , mut n : usize ) -> Option < Self :: Item > {
1075+ while let Some ( x) = self . next ( ) {
1076+ if n == 0 { return Some ( x) }
1077+ n -= 1 ;
1078+ }
1079+ None
1080+ }
10681081 fn next_back ( & mut self ) -> Option < Self :: Item >
10691082 where A : DoubleEndedIterator + ExactSizeIterator ,
10701083 B : DoubleEndedIterator + ExactSizeIterator ;
@@ -1094,6 +1107,11 @@ impl<A, B> ZipImpl<A, B> for Zip<A, B>
10941107 } )
10951108 }
10961109
1110+ #[ inline]
1111+ default fn nth ( & mut self , n : usize ) -> Option < Self :: Item > {
1112+ self . super_nth ( n)
1113+ }
1114+
10971115 #[ inline]
10981116 default fn next_back ( & mut self ) -> Option < ( A :: Item , B :: Item ) >
10991117 where A : DoubleEndedIterator + ExactSizeIterator ,
@@ -1174,6 +1192,24 @@ impl<A, B> ZipImpl<A, B> for Zip<A, B>
11741192 ( len, Some ( len) )
11751193 }
11761194
1195+ #[ inline]
1196+ fn nth ( & mut self , n : usize ) -> Option < Self :: Item > {
1197+ let delta = cmp:: min ( n, self . len - self . index ) ;
1198+ let end = self . index + delta;
1199+ while self . index < end {
1200+ let i = self . index ;
1201+ self . index += 1 ;
1202+ if A :: may_have_side_effect ( ) {
1203+ unsafe { self . a . get_unchecked ( i) ; }
1204+ }
1205+ if B :: may_have_side_effect ( ) {
1206+ unsafe { self . b . get_unchecked ( i) ; }
1207+ }
1208+ }
1209+
1210+ self . super_nth ( n - delta)
1211+ }
1212+
11771213 #[ inline]
11781214 fn next_back ( & mut self ) -> Option < ( A :: Item , B :: Item ) >
11791215 where A : DoubleEndedIterator + ExactSizeIterator ,
0 commit comments