Lifetime of a returned iterator

You don't declare lifetimes. Lifetimes come from the shape of your code, so to change what the lifetimes are, you must change the shape of the code.

In this case the issue is that the mutable reference to self is moved into the closure, but the iterator over v must exist at the same time. Unfortunately, mutable references must have exclusive access, so you can't have a mutable reference in the closure together with that iterator, as the mutable reference would then not have exclusive access to the stuff in the vector.

There's also the issue that move is missing on the closure, but it wont solve the problem to add it.

Does get_tuple_index need mutable access to self?

1 Like