1use crate::*;
2
3impl<T: Clone> Row<T> {
4 pub fn new(width: usize, initial_value: T) -> Self {
5 Row {
6 cells: {
7 let mut row = Vec::with_capacity(width);
8
9 for x in 0..width {
10 row.insert(x, initial_value.clone());
11 }
12
13 row
14 }
15 }
16 }
17}
18
19
20impl<T: Clone> Grid<T> {
21 pub fn new(width: usize, height: usize, initial_value: T) -> Self {
22 Grid {
23 rows: {
24 let initial_row = Row::new(width, initial_value);
25
26 let mut cells = Vec::with_capacity(height);
27
28 for y in 0..height {
29 cells.insert(y, initial_row.clone());
30 }
31
32 cells
33 }
34 }
35 }
36}