@@ -825,6 +825,19 @@ impl<A, D: Dimension> AxisIterCore<A, D> {
825
825
} ;
826
826
( left, right)
827
827
}
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
+ }
828
841
}
829
842
830
843
impl < A , D > Iterator for AxisIterCore < A , D >
@@ -1299,8 +1312,9 @@ macro_rules! chunk_iter_impl {
1299
1312
type Item = $array<' a, A , D >;
1300
1313
1301
1314
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) )
1304
1318
}
1305
1319
1306
1320
fn size_hint( & self ) -> ( usize , Option <usize >) {
@@ -1314,8 +1328,8 @@ macro_rules! chunk_iter_impl {
1314
1328
{
1315
1329
fn next_back( & mut self ) -> Option <Self :: Item > {
1316
1330
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) )
1319
1333
}
1320
1334
}
1321
1335
0 commit comments