struct A {
fp: u32,
section: Vec<B>
}
struct B{}
impl A {
pub fn instance(&mut self) {
self.fp = 0;
for item in self.section.iter() {
self.run(&item);
}
}
pub fn run(&mut self, _code: &B) {
// ...
self.fp = 1;
}
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0502]: cannot borrow `*self` as mutable because it is also borrowed as immutable
--> src/lib.rs:13:13
|
12 | for item in self.section.iter() {
| -------------------
| |
| immutable borrow occurs here
| immutable borrow later used here
13 | self.run(&item);
| ^^^^^^^^^^^^^^^ mutable borrow occurs here
For more information about this error, try `rustc --explain E0502`.
error: could not compile `playground` (lib) due to previous error