Skip to content

Commit

Permalink
derive Clone for GridRowIter/GridColIter
Browse files Browse the repository at this point in the history
  • Loading branch information
mirsella authored and becheran committed Dec 15, 2023
1 parent 64dc119 commit 664db9a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,10 +1515,12 @@ impl<T: Eq> PartialEq for Grid<T> {

impl<T: Eq> Eq for Grid<T> {}

#[derive(Clone)]
pub struct GridRowIter<'a, T> {
grid: &'a Grid<T>,
row_index: usize,
}
#[derive(Clone)]
pub struct GridColIter<'a, T> {
grid: &'a Grid<T>,
col_index: usize,
Expand Down Expand Up @@ -2951,6 +2953,26 @@ mod test {
assert_eq!(grid, grid![[4,1][5,2][6,3]]);
}

#[test]
fn iter_cols_clone() {
let grid = grid![[1,2,3][4,5,6]];
let mut cols = grid.iter_cols().skip(1);
let c3: u8 = cols.clone().nth(1).unwrap().sum();
let c2: u8 = cols.next().unwrap().sum();
assert_eq!(c2, 2 + 5);
assert_eq!(c3, 3 + 6);
}

#[test]
fn iter_rows_clone() {
let grid = grid![[1,2,3][4,5,6][7,8,9]];
let mut rows = grid.iter_rows().skip(1);
let r3: u8 = rows.clone().nth(1).unwrap().sum();
let r2: u8 = rows.next().unwrap().sum();
assert_eq!(r2, 4 + 5 + 6);
assert_eq!(r3, 7 + 8 + 9);
}

#[cfg(feature = "serde")]
mod serde_tests {
use super::*;
Expand Down

0 comments on commit 664db9a

Please sign in to comment.