I am attempting to encapsulate the event loop execution of glutin/winit in a custom class described in the example section over here: https://docs.rs/glutin/0.26.0/glutin/window/struct.Window.html
Now I am running into the issue of handling the ownership of self
members when attempting to access them in a closure passed to a method:
pub struct GameWindow {
context: ContextWrapper<PossiblyCurrent, Window>,
event_loop: EventLoop<()>,
gl: Rc<gl::Gl>,
}
impl GameWindow {
pub fn run(&self) {
self.event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit;
}
Event::MainEventsCleared => {
unsafe {
self.gl.Clear(gl::COLOR_BUFFER_BIT);
}
self.context.swap_buffers().unwrap();
}
_ => (),
}
});
}
}
The compiler complains with the following error: self
has an anonymous lifetime '_
but it needs to satisfy a 'static
lifetime requirement.
Applying that suggestion (even though I am not familiar with the static lifetime yet) yields an error about accessing self.event_loop
: Cannot move out of self.event_loop which is behind a shared reference.
What is a proper way to resolve this issue?