diff --git a/src/lib.rs b/src/lib.rs index fd553d0..5f2346a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,6 +160,16 @@ impl Grid { } } +impl Clone for Grid { + fn clone(&self) -> Self { + Grid { + rows: self.rows, + cols: self.cols, + data: self.data.clone(), + } + } +} + impl Index for Grid { type Output = [T]; @@ -185,6 +195,15 @@ impl IndexMut for Grid { mod test { use super::*; + #[test] + fn clone() { + let grid = grid![[1, 2, 3][4, 5, 6]]; + let mut clone = grid.clone(); + clone[0][2] = 10; + assert_eq!(grid[0][2], 3); + assert_eq!(clone[0][2], 10); + } + #[test] fn macro_init() { let grid = grid![[1, 2, 3][4, 5, 6]];