Skip to content

Commit 691ddef

Browse files
committed
Add move iterator + reference intoiter impl for ArrayBase
1 parent fb60b55 commit 691ddef

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern crate byteorder;
77

88
use std::mem;
99
use std::slice;
10+
use std::vec;
1011

1112
mod impls;
1213

@@ -157,6 +158,26 @@ impl<T> ArrayBase<T> {
157158
}
158159
}
159160

161+
impl<T> IntoIterator for ArrayBase<T> {
162+
type Item = T;
163+
type IntoIter = ArrayBaseIntoIter<T>;
164+
165+
fn into_iter(self) -> ArrayBaseIntoIter<T> {
166+
ArrayBaseIntoIter {
167+
inner: self.data.into_iter()
168+
}
169+
}
170+
}
171+
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+
160181
impl<T> Array<T> for ArrayBase<T> {
161182
fn dimension_info<'a>(&'a self) -> &'a [DimensionInfo] {
162183
&*self.info
@@ -208,6 +229,26 @@ impl<T> InternalMutableArray<T> for ArrayBase<T> {
208229
}
209230
}
210231

232+
/// An iterator over values of an `ArrayBase` in the higher-dimensional
233+
/// equivalent of row major order.
234+
pub struct ArrayBaseIntoIter<T> {
235+
inner: vec::IntoIter<T>,
236+
}
237+
238+
impl<T> Iterator for ArrayBaseIntoIter<T> {
239+
type Item = T;
240+
241+
fn next(&mut self) -> Option<T> {
242+
self.inner.next()
243+
}
244+
}
245+
246+
impl<T> DoubleEndedIterator for ArrayBaseIntoIter<T> {
247+
fn next_back(&mut self) -> Option<T> {
248+
self.inner.next_back()
249+
}
250+
}
251+
211252
enum ArrayParent<'parent, T:'static> {
212253
Slice(&'parent ArraySlice<'static, T>),
213254
MutSlice(&'parent MutArraySlice<'static, T>),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy