@@ -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,12 @@ 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+ {
1113+ self . super_nth ( n)
1114+ }
1115+
10971116 #[ inline]
10981117 default fn next_back ( & mut self ) -> Option < ( A :: Item , B :: Item ) >
10991118 where A : DoubleEndedIterator + ExactSizeIterator ,
@@ -1174,6 +1193,25 @@ impl<A, B> ZipImpl<A, B> for Zip<A, B>
11741193 ( len, Some ( len) )
11751194 }
11761195
1196+ #[ inline]
1197+ fn nth ( & mut self , n : usize ) -> Option < Self :: Item >
1198+ {
1199+ let delta = cmp:: min ( n, self . len - self . index ) ;
1200+ let end = self . index + delta;
1201+ while self . index < end {
1202+ let i = self . index ;
1203+ self . index += 1 ;
1204+ if A :: may_have_side_effect ( ) {
1205+ unsafe { self . a . get_unchecked ( i) ; }
1206+ }
1207+ if B :: may_have_side_effect ( ) {
1208+ unsafe { self . b . get_unchecked ( i) ; }
1209+ }
1210+ }
1211+
1212+ self . super_nth ( n - delta)
1213+ }
1214+
11771215 #[ inline]
11781216 fn next_back ( & mut self ) -> Option < ( A :: Item , B :: Item ) >
11791217 where A : DoubleEndedIterator + ExactSizeIterator ,
0 commit comments