Here's my code, the error is in the code.
struct BorrowMisunderstanding{
vector: Vec<i32>,
third_value: i32
}
impl BorrowMisunderstanding{
pub fn stuff(&mut self) -> &mut Self{
// v <====== immutable borrow occurs here
for (i, number) in self.vector.iter().enumerate(){
if i == 3{
// cannot borrow `*self` as mutable because it is also borrowed as immutable
self.inner_stuff(number);
//self.third_value = *number; // I can do that no big of a deal
return self;
}
}
self
}
fn inner_stuff(&mut self, number: &i32){
// do stuff but in another function instead of doing a billion and a half thing in one
self.third_value = *number;
}
}```
I welcome any suggestion to try another design, I did it the way I would do in javascript or C. Suppose I should do it more functionally? I have no idea how.
Thank you