I'm struggling to pass a method as a callback function, when calling connect_activate()
on a gtk::Application
, as shown in the code below. I've made a closure to avoid troubles concerning the &self
argument, but now I cannot fix this lifetime issues error[E0521]: borrowed data escapes outside of associated function.
What would be the easiest (and preferably idiomatic) way to deal with this error?
I need the callbacks (not only this first one) to access the struct fields. The idea is that every widget that needs to be manipulated by the application will be accessible through the GUI
struct.
struct GUI {
app: Application,
builder: Builder
}
impl GUI {
// ... (code omitted)
pub fn config(&self) {
let callback = |app| self.on_activate(app);
self.app.connect_activate(callback);
}
pub fn on_activate<'a>(&self, app: &'a Application) {
self.builder.set_application(app);
self.builder.add_from_file(UI_FILE).expect(ERR_FAILED_LOADING_UI);
let win : ApplicationWindow = self.builder.object("win").expect(
&format!("{} {}", ERR_OBJECT_NOT_FOUND, "win"));
win.show_all();
}
}