How to make a Rust singleton's destructor run?
问题 These are the ways I know of to create singletons in Rust: #[macro_use] extern crate lazy_static; use std::sync::{Mutex, Once, ONCE_INIT}; #[derive(Debug)] struct A(usize); impl Drop for A { fn drop(&mut self) { // This is never executed automatically. println!( "Dropping {:?} - Important stuff such as release file-handles etc.", *self ); } } // ------------------ METHOD 0 ------------------- static PLAIN_OBJ: A = A(0); // ------------------ METHOD 1 ------------------- lazy_static! { static