我想增加Rust和GTK-RS應用程序的結構,但我無法弄清楚如何處理事件連接。我發現問題存在於錯誤的一生中,但我並不真正瞭解它是如何解決的。類型必須滿足靜態生命週期
#[derive(Debug)]
struct CreatingProfileUI {
window: gtk::MessageDialog,
profile_name_entry: gtk::Entry,
add_btn: gtk::Button,
cancel_btn: gtk::Button,
}
#[derive(Debug)]
struct UI {
window: gtk::Window,
// Header
url_entry: gtk::Entry,
open_btn: gtk::Button,
// Body
add_profile_btn: gtk::Button,
remove_profile_btn: gtk::Button,
profiles_textview: gtk::TextView,
// Creating profile
creating_profile: CreatingProfileUI,
// Statusbar
statusbar: gtk::Statusbar,
}
impl UI {
fn init(&self) {
self.add_profile_btn
.connect_clicked(move |_| { &self.creating_profile.window.run(); });
}
}
而且我得到這個錯誤:
error[E0477]: the type `[[email protected]/main.rs:109:46: 111:6 self:&UI]` does not fulfill the required lifetime
--> src/main.rs:109:30
|
109 | self.add_profile_btn.connect_clicked(move |_| {
| ^^^^^^^^^^^^^^^
|
= note: type must satisfy the static lifetime
['ButtonExt :: connect_clicked'](https://docs.rs/gtk/0.2.0/gtk/trait.ButtonExt.html#tymethod.connect_clicked)確實需要一個帶''static''生命週期的函數。相關(圍繞線程,但錯誤是一樣的):https://stackoverflow.com/a/28661524/1233251 –