I’m trying to write a code which borrow a mutable copy of the last member of a vector and then change another member of the vector. There is a check that the vector has more than 2 elements so there is no changes to the same element.
pub fn adjust(&mut self) {
if self.vec.len() < 2 {
return;
}
let vec_last = self.vec.last_mut().unwrap();
let mut iter = vec_last.iter_mut();
while let Some(i) = iter.next() {
self.vec[0].push(i.clone());
}
}
The compiler produces the error cannot borrow self.vec as mutable more than once at a time
which is expected.
Is there a way to do such changes without triggering the error?
Cheers