Mutable column iterator

sorry, when I looked at the api docs of grid_2d, I saw several mut iterators and thought I saw columns, but indeed they don't have that.

I had a try in the playground. The lifetime problem boils down to this: The contract of the Iterator trait basically says: "If you have a &mut to Self, you can call next, for any lifetime of the &mut Self". Where as you would like to say:

fn next(self: &'a mut Self) -> Option<Self::Item>

Basically saying I only implement next when the reference outlives 'a, which doesn't uphold the contract of the trait. So I thought you need to specify that you only implement iterator in that case, rather than saying I only implement next. So I tried with:

impl<'a, ElemT: Primitive> Iterator for &'a mut ColumnIterMut<'a, ElemT>

But unfortunately I don't manage to dereference the self to get a &'a mut ColumnIterMut<'a, ElemT> out of it.

As from this earlier thread though it seems it's not possible without GAT's, which would allow you to tie the lifetime in the associated type to the lifetime of self. The use of a the streaming-iterator crate is suggested.

As an alternative, you could make ColumnIterMut static by using Rc<RefCell<Vec<ElemT>>> or Arc<Mutex<Vec<ElemT>>>. It obviously implies locking and some overhead, but it would guarantee that if you hold a ColumnIterMut, all required memory is still alive.