summaryrefslogtreecommitdiffstats
path: root/src/grid.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-12-08 01:09:33 -0500
committerJesse Luehrs <doy@tozt.net>2022-12-08 01:09:33 -0500
commitc44b43f33e0e4fedb38ea490cff9f357079e9c12 (patch)
tree4d8ac59bcfa7c84f45091a1e29d8e78d3efc2e9b /src/grid.rs
parent335dfe990b043e6695a0bb463694cf4dfc44f17a (diff)
downloadadvent-of-code-c44b43f33e0e4fedb38ea490cff9f357079e9c12.tar.gz
advent-of-code-c44b43f33e0e4fedb38ea490cff9f357079e9c12.zip
simplify
Diffstat (limited to 'src/grid.rs')
-rw-r--r--src/grid.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/grid.rs b/src/grid.rs
index b84e1b7..f360932 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -110,10 +110,24 @@ impl<T: Default + Clone + Eq + PartialEq> Grid<T> {
Row(self.rows.len())
}
+ pub fn each_row(
+ &self,
+ ) -> impl Iterator<Item = Row> + DoubleEndedIterator + ExactSizeIterator
+ {
+ (0..self.rows().0).map(Row)
+ }
+
pub fn cols(&self) -> Col {
Col(self.rows[0].cells.len())
}
+ pub fn each_col(
+ &self,
+ ) -> impl Iterator<Item = Col> + DoubleEndedIterator + ExactSizeIterator
+ {
+ (0..self.cols().0).map(Col)
+ }
+
pub fn get(&self, row: Row) -> Option<&GridRow<T>> {
self.rows.get(row.0)
}