#[derive(Default)]
pub struct Module {
section: Section
}
#[derive(Default)]
pub struct Section {
pub code: Vec<Code>
}
#[derive(Default)]
pub struct Code{}
impl Module {
pub fn run(&mut self, _code: &Vec<Code>){
// self must be mut
}
}
fn main() {
let mut module = Module::default();
let code = &module.section.code;
module.run(code);
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0502]: cannot borrow `module` as mutable because it is also borrowed as immutable
--> src/main.rs:27:5
|
26 | let code = &module.section.code;
| -------------------- immutable borrow occurs here
27 | module.run(code);
| ^^^^^^^---^^^^^^
| | |
| | immutable borrow later used by call
| mutable borrow occurs here
For more information about this error, try `rustc --explain E0502`.
error: could not compile `playground` (bin "playground") due to previous error