Skip to content

Commit

Permalink
Merge pull request #16 from HarrisonMc555/iter-impl-clone
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonMc555 authored Nov 23, 2022
2 parents 7567b4a + 131ad20 commit 3fc417f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ impl<T> Array2D<T> {
///
/// [`Iterator`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html
/// [row major order]: https://en.wikipedia.org/wiki/Row-_and_column-major_order
pub fn elements_row_major_iter(&self) -> impl DoubleEndedIterator<Item = &T> {
pub fn elements_row_major_iter(&self) -> impl DoubleEndedIterator<Item = &T> + Clone {
self.array.iter()
}

Expand All @@ -837,7 +837,7 @@ impl<T> Array2D<T> {
///
/// [`Iterator`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html
/// [column major order]: https://en.wikipedia.org/wiki/Row-_and_column-major_order
pub fn elements_column_major_iter(&self) -> impl DoubleEndedIterator<Item = &T> {
pub fn elements_column_major_iter(&self) -> impl DoubleEndedIterator<Item = &T> + Clone {
self.indices_column_major().map(move |i| &self[i])
}

Expand Down Expand Up @@ -938,7 +938,7 @@ impl<T> Array2D<T> {
/// [`Item`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#associatedtype.Item
pub fn rows_iter(
&self,
) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = &T>> {
) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = &T>> + Clone {
(0..self.num_rows()).map(move |row_index| {
self.row_iter(row_index)
.expect("rows_iter should never fail")
Expand Down Expand Up @@ -988,7 +988,7 @@ impl<T> Array2D<T> {
/// [`Item`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#associatedtype.Item
pub fn columns_iter(
&self,
) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = &T>> {
) -> impl DoubleEndedIterator<Item = impl DoubleEndedIterator<Item = &T>> + Clone {
(0..self.num_columns).map(move |column_index| {
self.column_iter(column_index)
.expect("columns_iter should never fail")
Expand Down Expand Up @@ -1116,7 +1116,7 @@ impl<T> Array2D<T> {
/// ```
///
/// [`usize`]: https://doc.rust-lang.org/std/primitive.usize.html
pub fn indices_row_major(&self) -> impl DoubleEndedIterator<Item = (usize, usize)> {
pub fn indices_row_major(&self) -> impl DoubleEndedIterator<Item = (usize, usize)> + Clone {
indices_row_major(self.num_rows, self.num_columns)
}

Expand All @@ -1139,7 +1139,7 @@ impl<T> Array2D<T> {
/// ```
///
/// [`usize`]: https://doc.rust-lang.org/std/primitive.usize.html
pub fn indices_column_major(&self) -> impl DoubleEndedIterator<Item = (usize, usize)> {
pub fn indices_column_major(&self) -> impl DoubleEndedIterator<Item = (usize, usize)> + Clone {
indices_column_major(self.num_rows, self.num_columns)
}

Expand Down Expand Up @@ -1167,7 +1167,7 @@ impl<T> Array2D<T> {
/// # }
///
/// [`usize`]: https://doc.rust-lang.org/std/primitive.usize.html
pub fn enumerate_row_major(&self) -> impl DoubleEndedIterator<Item = ((usize, usize), &T)> {
pub fn enumerate_row_major(&self) -> impl DoubleEndedIterator<Item = ((usize, usize), &T)> + Clone {
self.indices_row_major().map(move |i| (i, &self[i]))
}

Expand Down Expand Up @@ -1195,7 +1195,7 @@ impl<T> Array2D<T> {
/// # }
///
/// [`usize`]: https://doc.rust-lang.org/std/primitive.usize.html
pub fn enumerate_column_major(&self) -> impl DoubleEndedIterator<Item = ((usize, usize), &T)> {
pub fn enumerate_column_major(&self) -> impl DoubleEndedIterator<Item = ((usize, usize), &T)> + Clone {
self.indices_column_major().map(move |i| (i, &self[i]))
}

Expand Down Expand Up @@ -1271,13 +1271,13 @@ fn flatten<T: Clone>(nested: &[Vec<T>]) -> Vec<T> {
fn indices_row_major(
num_rows: usize,
num_columns: usize,
) -> impl DoubleEndedIterator<Item = (usize, usize)> {
) -> impl DoubleEndedIterator<Item = (usize, usize)> + Clone {
(0..num_rows).flat_map(move |row| (0..num_columns).map(move |column| (row, column)))
}

fn indices_column_major(
num_rows: usize,
num_columns: usize,
) -> impl DoubleEndedIterator<Item = (usize, usize)> {
) -> impl DoubleEndedIterator<Item = (usize, usize)> + Clone {
(0..num_columns).flat_map(move |column| (0..num_rows).map(move |row| (row, column)))
}

0 comments on commit 3fc417f

Please sign in to comment.