The code is something like the following, in a function that is an implementation for a Context
struct, defined as the following:
struct Context {
lines: isize,
buffer: Vec<String>,
history: Vec<Box<Instruction>>,
}
And the function, of course as an implementation:
fn _execute_history(&mut self, instruction: &Instruction) -> Reaction {
let num = instruction.suffix.parse::<usize>();
match num {
Ok(number) => {
match self.history.get(number) {
Some(ins) => { return self.execute(*ins); },
_ => { /* Error handling */ }
}
}
Err(..) => { /* Error handling */ }
}
}
This doesn't compile and I don't understand the error message. I searched online for similar problems and I cannot seem to grasp the problem here. I am from a Python background. The full error:
hello.rs:72:23: 72:35 note: previous borrow of `self.history[..]` occurs here; the immutable
borrow prevents subsequent moves or mutable borrows of `self.history[..]` until the borrow ends
I am fully aware that the function is not conforming to the type system, but this is because the simplified code is for demonstrative purposes only.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…