Hi, I've just started a tutorial on how to initialize a simple application with Vulkan as an excuse to exercise my rust skills. It's been two weeks since I've started with rust and I've never stumbled in this kind of error...
Here the compiler is telling me that i can't move the event_loop object out self
because it lies behind a mutable reference.
What i don't understand specifically is:
- Why is a move even occurring in this case?
- Why can't i move some B
out of some else A
if i tell the compiler that A
is mutable?
Here the full error:
error[E0507]: cannot move out of `self.event_loop` which is behind a mutable reference
--> src/main.rs:33:13
|
33 | self.event_loop.run(move |event, _, _| {
| ^^^^^^^^^^^^^^^ move occurs because `self.event_loop` has type `winit::event_loop::EventLoop<()>`, which does not implement the `Copy` trait
Code:
struct HelloTriangleApplication {
event_loop: EventLoop<()>
}
impl HelloTriangleApplication {
pub fn init() -> Self {
let event_loop = Self::init_window();
Self {
event_loop
}
}
fn init_window() -> EventLoop<()> {
let event_loop = EventLoop::new();
let _window = WindowBuilder::new()
.with_title("Vulkan tutorial")
//.with_dimensions(LogicalSize::new(f64::from(WIDTH), f64::from(HEIGHT)))
.build(&event_loop);
event_loop
}
fn main_loop(&mut self) {
loop {
let mut done: bool = false;
self.event_loop.run(move |event, _, _| {
if let Event::WindowEvent { event: WindowEvent::CloseRequested, .. } = event {
done = true
}
if done {
return;
}
});
}
}
}