grid: add add_mut()

This commit is contained in:
2024-12-15 23:21:52 -08:00
parent 6283ff37f9
commit 2cf8527c4f
3 changed files with 7 additions and 1 deletions

View File

@ -181,6 +181,12 @@ impl<T: Clone + Eq + PartialEq + Debug> Grid<T> {
None => None,
}
}
pub fn get_mut<C: AsCoord2d>(&mut self, c: &C) -> Option<&mut T> {
match self.valid_pos(c) {
Some(pos) => Some(self.data.get_mut(pos).unwrap()),
None => None,
}
}
pub fn set<C: AsCoord2d>(&mut self, c: &C, mut val: T) -> Option<T> {
match self.valid_pos(c) {
Some(pos) => {