I have a struct containing a 2D array:
struct Block;
struct World {
blocks: [[Block; 10]; 10],
}
How could I write a function which returns an iterator over a 2D array, but with the enumeration indices included?
fn enumerate_blocks(&self) -> impl Iterator<Item = (usize, usize, &Block)>
I managed to write an implementation of the function which just returns an iterator without enumeration indices:
fn blocks(&self) -> impl Iterator<Item = &Block> {
self.blocks.iter().flat_map(|x| x.iter())
}
If I call Iterator::enumerate once, I will get an iterator over (usize, [B; 10])s. What I can do next to get an iterator over (usize, usize, B)s?
I know I could make the function return a custom struct then implement Iterator, like image does, but ideally I would like to avoid this.