@@ -151,10 +151,38 @@ impl<T> ArrayBase<T> {
151
151
self . data . extend ( other. data . into_iter ( ) ) ;
152
152
}
153
153
154
- /// Returns an iterator over the values in this array, in the
154
+ /// Returns an iterator over references to the values in this array, in the
155
155
/// higher-dimensional equivalent of row-major order.
156
- pub fn values < ' a > ( & ' a self ) -> slice:: Iter < ' a , T > {
157
- self . data . iter ( )
156
+ pub fn iter < ' a > ( & ' a self ) -> ArrayBaseIter < ' a , T > {
157
+ ArrayBaseIter {
158
+ inner : self . data . iter ( ) ,
159
+ }
160
+ }
161
+
162
+ /// Returns an iterator over references to the values in this array, in the
163
+ /// higher-dimensional equivalent of row-major order.
164
+ pub fn iter_mut < ' a > ( & ' a mut self ) -> ArrayBaseIterMut < ' a , T > {
165
+ ArrayBaseIterMut {
166
+ inner : self . data . iter_mut ( ) ,
167
+ }
168
+ }
169
+ }
170
+
171
+ impl < ' a , T : ' a > IntoIterator for & ' a ArrayBase < T > {
172
+ type Item = & ' a T ;
173
+ type IntoIter = ArrayBaseIter < ' a , T > ;
174
+
175
+ fn into_iter ( self ) -> ArrayBaseIter < ' a , T > {
176
+ self . iter ( )
177
+ }
178
+ }
179
+
180
+ impl < ' a , T : ' a > IntoIterator for & ' a mut ArrayBase < T > {
181
+ type Item = & ' a mut T ;
182
+ type IntoIter = ArrayBaseIterMut < ' a , T > ;
183
+
184
+ fn into_iter ( self ) -> ArrayBaseIterMut < ' a , T > {
185
+ self . iter_mut ( )
158
186
}
159
187
}
160
188
@@ -169,15 +197,6 @@ impl<T> IntoIterator for ArrayBase<T> {
169
197
}
170
198
}
171
199
172
- impl < ' a , T > IntoIterator for & ' a ArrayBase < T > {
173
- type Item = & ' a T ;
174
- type IntoIter = slice:: Iter < ' a , T > ;
175
-
176
- fn into_iter ( self ) -> slice:: Iter < ' a , T > {
177
- self . values ( )
178
- }
179
- }
180
-
181
200
impl < T > Array < T > for ArrayBase < T > {
182
201
fn dimension_info < ' a > ( & ' a self ) -> & ' a [ DimensionInfo ] {
183
202
& * self . info
@@ -229,8 +248,48 @@ impl<T> InternalMutableArray<T> for ArrayBase<T> {
229
248
}
230
249
}
231
250
251
+ /// An iterator over references to values of an `ArrayBase` in the
252
+ /// higher-dimensional equivalent of row-major order.
253
+ pub struct ArrayBaseIter < ' a , T : ' a > {
254
+ inner : slice:: Iter < ' a , T > ,
255
+ }
256
+
257
+ impl < ' a , T : ' a > Iterator for ArrayBaseIter < ' a , T > {
258
+ type Item = & ' a T ;
259
+
260
+ fn next ( & mut self ) -> Option < & ' a T > {
261
+ self . inner . next ( )
262
+ }
263
+ }
264
+
265
+ impl < ' a , T : ' a > DoubleEndedIterator for ArrayBaseIter < ' a , T > {
266
+ fn next_back ( & mut self ) -> Option < & ' a T > {
267
+ self . inner . next_back ( )
268
+ }
269
+ }
270
+
271
+ /// An iterator over mutable references to values of an `ArrayBase` in the
272
+ /// higher-dimensional equivalent of row-major order.
273
+ pub struct ArrayBaseIterMut < ' a , T : ' a > {
274
+ inner : slice:: IterMut < ' a , T > ,
275
+ }
276
+
277
+ impl < ' a , T : ' a > Iterator for ArrayBaseIterMut < ' a , T > {
278
+ type Item = & ' a mut T ;
279
+
280
+ fn next ( & mut self ) -> Option < & ' a mut T > {
281
+ self . inner . next ( )
282
+ }
283
+ }
284
+
285
+ impl < ' a , T : ' a > DoubleEndedIterator for ArrayBaseIterMut < ' a , T > {
286
+ fn next_back ( & mut self ) -> Option < & ' a mut T > {
287
+ self . inner . next_back ( )
288
+ }
289
+ }
290
+
232
291
/// An iterator over values of an `ArrayBase` in the higher-dimensional
233
- /// equivalent of row major order.
292
+ /// equivalent of row- major order.
234
293
pub struct ArrayBaseIntoIter < T > {
235
294
inner : vec:: IntoIter < T > ,
236
295
}
0 commit comments