小编Inf*_*ion的帖子

类型必须满足静态生命周期

我正在尝试增加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(); });
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

error[E0477]: the type `[closure@src/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 |_| {
    | …
Run Code Online (Sandbox Code Playgroud)

gtk rust gtk-rs

5
推荐指数
1
解决办法
1213
查看次数

标签 统计

gtk ×1

gtk-rs ×1

rust ×1