Skip to content

Commit 5a4c401

Browse files
committed
FIX: Move LaneIter related items to iterators::lanes
1 parent 281d17c commit 5a4c401

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

src/iterators/lanes.rs

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::marker::PhantomData;
22

3-
use super::LanesIter;
4-
use super::LanesIterMut;
53
use crate::imp_prelude::*;
64
use crate::{Layout, NdProducer};
5+
use crate::iterators::Baseiter;
76

87
impl_ndproducer! {
98
['a, A, D: Dimension]
@@ -142,3 +141,92 @@ where
142141
}
143142
}
144143
}
144+
145+
/// An iterator that traverses over all axes but one, and yields a view for
146+
/// each lane along that axis.
147+
///
148+
/// See [`.lanes()`](../struct.ArrayBase.html#method.lanes) for more information.
149+
pub struct LanesIter<'a, A, D> {
150+
inner_len: Ix,
151+
inner_stride: Ixs,
152+
iter: Baseiter<A, D>,
153+
life: PhantomData<&'a A>,
154+
}
155+
156+
clone_bounds!(
157+
['a, A, D: Clone]
158+
LanesIter['a, A, D] {
159+
@copy {
160+
inner_len,
161+
inner_stride,
162+
life,
163+
}
164+
iter,
165+
}
166+
);
167+
168+
impl<'a, A, D> Iterator for LanesIter<'a, A, D>
169+
where
170+
D: Dimension,
171+
{
172+
type Item = ArrayView<'a, A, Ix1>;
173+
fn next(&mut self) -> Option<Self::Item> {
174+
self.iter.next().map(|ptr| unsafe {
175+
ArrayView::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
176+
})
177+
}
178+
179+
fn size_hint(&self) -> (usize, Option<usize>) {
180+
self.iter.size_hint()
181+
}
182+
}
183+
184+
impl<'a, A, D> ExactSizeIterator for LanesIter<'a, A, D>
185+
where
186+
D: Dimension,
187+
{
188+
fn len(&self) -> usize {
189+
self.iter.len()
190+
}
191+
}
192+
193+
// NOTE: LanesIterMut is a mutable iterator and must not expose aliasing
194+
// pointers. Due to this we use an empty slice for the raw data (it's unused
195+
// anyway).
196+
/// An iterator that traverses over all dimensions but the innermost,
197+
/// and yields each inner row (mutable).
198+
///
199+
/// See [`.lanes_mut()`](../struct.ArrayBase.html#method.lanes_mut)
200+
/// for more information.
201+
pub struct LanesIterMut<'a, A, D> {
202+
inner_len: Ix,
203+
inner_stride: Ixs,
204+
iter: Baseiter<A, D>,
205+
life: PhantomData<&'a mut A>,
206+
}
207+
208+
impl<'a, A, D> Iterator for LanesIterMut<'a, A, D>
209+
where
210+
D: Dimension,
211+
{
212+
type Item = ArrayViewMut<'a, A, Ix1>;
213+
fn next(&mut self) -> Option<Self::Item> {
214+
self.iter.next().map(|ptr| unsafe {
215+
ArrayViewMut::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
216+
})
217+
}
218+
219+
fn size_hint(&self) -> (usize, Option<usize>) {
220+
self.iter.size_hint()
221+
}
222+
}
223+
224+
impl<'a, A, D> ExactSizeIterator for LanesIterMut<'a, A, D>
225+
where
226+
D: Dimension,
227+
{
228+
fn len(&self) -> usize {
229+
self.iter.len()
230+
}
231+
}
232+

src/iterators/mod.rs

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::Ix1;
2424
use super::{NdProducer, RemoveAxis};
2525

2626
pub use self::chunks::{ExactChunks, ExactChunksIter, ExactChunksIterMut, ExactChunksMut};
27-
pub use self::lanes::{Lanes, LanesMut};
27+
pub use self::lanes::{Lanes, LanesMut, LanesIter, LanesIterMut};
2828
pub use self::windows::Windows;
2929
pub(crate) use self::trusted::{to_vec, to_vec_mapped};
3030

@@ -742,94 +742,6 @@ where
742742
}
743743
}
744744

745-
/// An iterator that traverses over all axes but one, and yields a view for
746-
/// each lane along that axis.
747-
///
748-
/// See [`.lanes()`](../struct.ArrayBase.html#method.lanes) for more information.
749-
pub struct LanesIter<'a, A, D> {
750-
inner_len: Ix,
751-
inner_stride: Ixs,
752-
iter: Baseiter<A, D>,
753-
life: PhantomData<&'a A>,
754-
}
755-
756-
clone_bounds!(
757-
['a, A, D: Clone]
758-
LanesIter['a, A, D] {
759-
@copy {
760-
inner_len,
761-
inner_stride,
762-
life,
763-
}
764-
iter,
765-
}
766-
);
767-
768-
impl<'a, A, D> Iterator for LanesIter<'a, A, D>
769-
where
770-
D: Dimension,
771-
{
772-
type Item = ArrayView<'a, A, Ix1>;
773-
fn next(&mut self) -> Option<Self::Item> {
774-
self.iter.next().map(|ptr| unsafe {
775-
ArrayView::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
776-
})
777-
}
778-
779-
fn size_hint(&self) -> (usize, Option<usize>) {
780-
self.iter.size_hint()
781-
}
782-
}
783-
784-
impl<'a, A, D> ExactSizeIterator for LanesIter<'a, A, D>
785-
where
786-
D: Dimension,
787-
{
788-
fn len(&self) -> usize {
789-
self.iter.len()
790-
}
791-
}
792-
793-
// NOTE: LanesIterMut is a mutable iterator and must not expose aliasing
794-
// pointers. Due to this we use an empty slice for the raw data (it's unused
795-
// anyway).
796-
/// An iterator that traverses over all dimensions but the innermost,
797-
/// and yields each inner row (mutable).
798-
///
799-
/// See [`.lanes_mut()`](../struct.ArrayBase.html#method.lanes_mut)
800-
/// for more information.
801-
pub struct LanesIterMut<'a, A, D> {
802-
inner_len: Ix,
803-
inner_stride: Ixs,
804-
iter: Baseiter<A, D>,
805-
life: PhantomData<&'a mut A>,
806-
}
807-
808-
impl<'a, A, D> Iterator for LanesIterMut<'a, A, D>
809-
where
810-
D: Dimension,
811-
{
812-
type Item = ArrayViewMut<'a, A, Ix1>;
813-
fn next(&mut self) -> Option<Self::Item> {
814-
self.iter.next().map(|ptr| unsafe {
815-
ArrayViewMut::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
816-
})
817-
}
818-
819-
fn size_hint(&self) -> (usize, Option<usize>) {
820-
self.iter.size_hint()
821-
}
822-
}
823-
824-
impl<'a, A, D> ExactSizeIterator for LanesIterMut<'a, A, D>
825-
where
826-
D: Dimension,
827-
{
828-
fn len(&self) -> usize {
829-
self.iter.len()
830-
}
831-
}
832-
833745
#[derive(Debug)]
834746
struct AxisIterCore<A, D> {
835747
/// Index along the axis of the value of `.next()`, relative to the start

0 commit comments

Comments
 (0)