@@ -825,6 +825,19 @@ impl<A, D: Dimension> AxisIterCore<A, D> {
825825 } ;
826826 ( left, right)
827827 }
828+
829+ /// Does the same thing as `.next()` but also returns the index of the item
830+ /// relative to the start of the axis.
831+ fn next_with_index ( & mut self ) -> Option < ( usize , * mut A ) > {
832+ let index = self . index ;
833+ self . next ( ) . map ( |ptr| ( index, ptr) )
834+ }
835+
836+ /// Does the same thing as `.next_back()` but also returns the index of the
837+ /// item relative to the start of the axis.
838+ fn next_back_with_index ( & mut self ) -> Option < ( usize , * mut A ) > {
839+ self . next_back ( ) . map ( |ptr| ( self . end , ptr) )
840+ }
828841}
829842
830843impl < A , D > Iterator for AxisIterCore < A , D >
@@ -1299,8 +1312,9 @@ macro_rules! chunk_iter_impl {
12991312 type Item = $array<' a, A , D >;
13001313
13011314 fn next( & mut self ) -> Option <Self :: Item > {
1302- let index = self . iter. index;
1303- self . iter. next( ) . map( |ptr| self . get_subview( index, ptr) )
1315+ self . iter
1316+ . next_with_index( )
1317+ . map( |( index, ptr) | self . get_subview( index, ptr) )
13041318 }
13051319
13061320 fn size_hint( & self ) -> ( usize , Option <usize >) {
@@ -1314,8 +1328,8 @@ macro_rules! chunk_iter_impl {
13141328 {
13151329 fn next_back( & mut self ) -> Option <Self :: Item > {
13161330 self . iter
1317- . next_back ( )
1318- . map( |ptr| self . get_subview( self . iter . end , ptr) )
1331+ . next_back_with_index ( )
1332+ . map( |( index , ptr) | self . get_subview( index , ptr) )
13191333 }
13201334 }
13211335
0 commit comments