I tried:
fn main() {
let mut vec = [1, 2, 3];
for mut x in &vec { *x = 3; }
for mut &x in &vec { x = 3; }
for mut *x in &vec { x = 3; }
for mut x in mut &vec { *x = 3; }
for mut x in &(mut vec) { *x = 3; }
}
None of these work; how should I do it?
I get errors like:
mut
must be attached to each individual binding
- expected identifier, found
*
- expected expression, found keyword
mut
- cannot assign to
*x
which is behind a &
reference
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…