This closure depends on self.running, and therefore can not live longer than the Application object we are calling from
However, rust has no idea what event_loop.run does -- that function might store the closure in a way such that the closure tries to outlive the Application.
As for how to fix this -- I'm not particularly sure, I've found Gui + Callbacks + Closures to be troublesome as well. I end up using lots of Rc<...>'s , but I don't know if it's the correct/idiomatic way to resolve this.
Hi thanks for you answer.
I experimented a little and according to the winit docs the closure in event_loop.run has a static lifetime.
I also found 2 Solutions
giving the self param of application.run a 'static lifetime specifier solved it but I guess that is the least idiomatic way since application doesn't really have a static lifetime.
Another way to solve it was to move the event_loop.run() call out of the application function an declaring the app variable in the same scope as event_loop. This way I could access it without specifying a lifetime.