In the function representing the implementation for the structure Context, the following code looks like this:
struct Context {
lines: isize,
buffer: Vec<String>,
history: Vec<Box<Instruction>>,
}
And the function, of course, is like 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); },
_ => { }
}
}
Err(..) => { }
}
}
This does not compile and I do not understand the error message. I searched online for similar problems and I cannot understand the problem here. I am in the background of Python. 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 fully understand that the function does not correspond to the type system, but this is due to the fact that the simplified code is intended for demonstration purposes only.
source
share