I am trying to populate the data of a Struct within a Struct by passing it to a function to fill it with random data. However I cant get either the iterator correct or I am once again confused with the borrow checker. How can I resolve this or am I going about this the wrong way?
let mut i = ships.iter();
for mut ship in i {
randomize_location(&mut rng, &mut ship.location);
I get:
error[E0596]: cannot borrow `ship.location` as mutable, as it is behind a `&` reference
--> src/main.rs:81:38
|
80 | for mut ship in i {
| - this iterator yields `&` references
81 | randomize_location(&mut rng, &mut ship.location);
| ^^^^^^^^^^^^^^^^^^ `ship` is a `&` reference, so the data it refers to cannot be borrowed as mutable