I can not get the following piece of code to work:
extern crate gtk
use gtk::prelude::*
use gtk::Window;
use gtk::WindowType;
// ...
static mut appWindow: Option<Window> = None;
fn main() {
// ...
appWindow = Some(Window::new(WindowType::Toplevel))
// ...
}
The compiler produces the error:
error: mutable statics are not allowed to have destructors [E0397]
static mut appWindow: Option<Window> = None;
Surrounding everything with unsafe { ... }
doesn't help.
Here's code that reproduces the same error that you've shown:
Produces the errors:
As the message says, Rust disallows having any kind of static item with destructors. A proposed change to the language discusses the origin of this:
RFC 1440 has been accepted to allow these types. As of Rust 1.9, there is an unstable feature that allows them:
#![feature(drop_types_in_const)]
.As the RFC says:
Which leads to an alternate solution before the feature is stabilized: you can create a non-mutable static variable with lazy_static, which can then be wrapped in a thread-safe mutability wrapper. The type may contain a destructor:
How do I create a global, mutable singleton?