Thank you! Yes, that seems to be exactly the issue. I’ve thought about this a bit, as this is a fairly old issue it’s unlikely to change any time soon, and I might abandon mutable iterators completely in my design.
Another option, as the base data structure is a Vec, might be to return a flattened iterator of vec.iter_mut for every 1D span (using their unsafe code!), though this sounds like a borrow-checking nightmare too.
Edit: the latter is also out of the question, I think
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
let (y1, y2) = (0, self.height);
(y1..y2).map(move |y| self.grid.iter_mut()).flatten()
}
gives me the same error as before:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
(but maybe I need to be more creative here with lifetime specifications)