Hello!
I'm trying to write a piece of code more concise, but I hit this roadblock:
Minimal (non)-working example:
error: cannot assign to data in a &
reference [E0389]
x.v = 0;
struct S {
v: i32,
}
struct P {
k: S,
l: S,
}
fn test() {
// Given:
let mut data = P {
k: S {v:1},
l: S {v:1}, // and possibly more ...
};
// Want to reset these, something like this:
for x in &[&mut data.k, &mut data.l] {
// Possibly do something here: func(x)
// Then reset:
x.v = 0; // <---------------- ERROR
}
}
I'm missing something here and I really can't find out what it is.
Any insight is very much appreciated!