meter :&'a mut Meter
}
fn main() {
let mut m = Meter {};
let mut three_phase_meter = Vec::<Phase>::new();
three_phase_meter.push(Phase { meter: &mut m });
three_phase_meter.push(Phase { meter: &mut m });
three_phase_meter.push(Phase { meter: &mut m });
}
error[E0499]: cannot borrow `m` as mutable more than once at a time
--> src/main.rs:13:48
|
12 | three_phase_meter.push(Phase { meter: &mut m });
| - first mutable borrow occurs here
13 | three_phase_meter.push(Phase { meter: &mut m });
| ^ second mutable borrow occurs here
14 | three_phase_meter.push(Phase { meter: &mut m });
15 | }
| - first borrow ends here
Как можно обойти?
RefCell, но лучше никак.
Зачем ты так делаешь?
https://play.rust-lang.org/?gist=225e3a763c166699ae23d7a9084bbd16&version=stable у меня как-то так получилось
Обсуждают сегодня