help me to understand this code.
and why drop function not called automaticaly
use std::ops::Drop;
static mut BASE_CORE: Option<Core> = None;
struct Core {
ver: String,
name: String
}
impl Core {
pub fn new() -> Core {
Core {
ver: String::from("some ver 0.0.0"),
name: String::from("Im Core")
}
}
}
impl Drop for Core {
fn drop(&mut self) {
println!("OnDrop: {} {}", self.ver, self.name);
}
}
struct Base {
astr: String
}
impl Base {
pub fn new () -> Base {
unsafe {
BASE_CORE = Some(Core::new());
}
Base {
astr: String::from("from base")
}
}
pub fn print_msg(&self) {
println!("{}", self.astr)
}
}
fn main() {
// var1 when exit drop function not called automaticaly
let var1 = Base::new();
var1.print_msg();
let _var2 = Core::new();
}