I have a piece of code that looks like this:
struct Block {
x: f32,
y: f32,
width: f32,
height: f32,
color: Color,
}
let mut blocks: Vec<Block> = Vec::new();
for block in blocks.iter() {
block.x = 0.0 - block.width;
}
I am trying to change the x
of all the blocks in the list but it gives an error:
error[E0594]: cannot assign to `block.x` which is behind a `&` reference
--> src/main.rs:14:9
|
13 | for block in blocks.iter() {
| ------------- this iterator yields `&` references
14 | block.x = 0.0 - block.width;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `block` is a `&` reference, so the data it refers to cannot be written
How do I fix this?