手機(jī)怎么建立微信公眾號贛州seo公司
Box就是unique_ptr
這個函數(shù)的功能是消費(fèi)box返回一個全局變量!
寫一個函數(shù),想要真的返回全局變量,感覺用這個是個好的做法
fn Foo()->Option<&'static mut A>
{let a = Box::new(A());Some(Box::leak(a))
}
這樣就能當(dāng)真拿到這個全局變量了
還有一種是lazy macro
use lazy_static::lazy_static;
然后包在里面
這是圣經(jīng)里的例子
static NAMES: Mutex<String> = Mutex::new(String::from("Sunface, Jack, Allen"));
GG error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
lazy_static! {static ref NAMES: Mutex<String> = Mutex::new(String::from("Sunface, Jack, Allen"));
}
OK