Created
August 4, 2017 23:48
-
-
Save umurgdk/50329332571a2c6c3f7cbf0d595fc35e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct TileRefMut<'a, T: Tile + 'a> { | |
pub tile: &'a mut T, | |
pub x: usize, | |
pub y: usize | |
} | |
pub struct IterMut<'a, T: Tile + 'a> { | |
tile_map: &'a mut TileMap<T>, | |
x: usize, | |
y: usize | |
} | |
impl<'a, T: Tile + 'a> Iterator for IterMut<'a, T> { | |
type Item = TileRefMut<'a, T>; | |
fn next(&mut self) -> Option<Self::Item> { | |
self.tile_map.at_mut(self.x, self.y).map(|t| { | |
let tile_ref = TileRefMut { tile: t, x: self.x, y: self.y }; | |
self.x += 1; | |
if self.x >= self.tile_map.width { | |
self.y += 1; | |
self.x = 0; | |
} | |
tile_ref | |
}) | |
} | |
} |
Author
umurgdk
commented
Aug 4, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment