鉴于此代码:
pub fn handle_events(&mut self) {
use self::glium::glutin::Event;
for ev in self.display.poll_events() {
match ev {
Event::Closed => self.state = GameState::Exiting,
Event::KeyboardInput(state, _, Some(key))
if self.input.keys_pressed.contains_key(&key) =>
self.handle_keyboard(state, key),
_ => (),
}
}
}
fn handle_keyboard(&mut self, state: ElementState, key: VirtualKeyCode) {
...
}
Rust 抱怨self.handle_keyboard(state, key)
说我不能借用 的可变引用self
,因为我已经self.display
在行中做了一个不可变的借用for ev in self.display.poll_events() {
。
如果我只想修改self
不在的字段self.display
,是否可以将其指定给编译器?它会是这样的:
fn handle_keyboard(&mut self.field, ...)