I am making a cross-platform terminal library. Since my library changes the state of the terminal, I need to return all the changes that are made to the terminal when the process is completed. Now I implement this function and think about ways to restore the initial state of the terminal at the end.
I thought that the static variable is initialized when the program starts, and that when the program ends, this static variable will be destroyed. Since my static variable is a structure that implements the trait Drop, it will be deleted at the end of the program, but this is not because the drop called line is never printed:
static mut SOME_STATIC_VARIABLE: SomeStruct = SomeStruct { some_value: None };
struct SomeStruct {
pub some_value: Option<i32>,
}
impl Drop for SomeStruct {
fn drop(&mut self) {
println!("drop called");
}
}
Why is it drop()not called when the program ends? My thoughts are wrong, and should I do it differently?
source
share