我想为全局变量赋值,但它一直有编译器错误:
static mut NameArr: [&'static str; 20] = ["\0"; 20];
fn main() {
unsafe {
static mut S1 :String = "".to_string();
S1.push('\0');
NameArr[0] = S1.as_slice();
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
a.rs:7:29: 7:43 error: mutable statics are not allowed to have destructors
a.rs:7 static mut S1 :String = "".to_string();
^~~~~~~~~~~~~~
a.rs:7:29: 7:43 error: static contains unimplemented expression type [E0019]
a.rs:7 static mut S1 :String = "".to_string();
^~~~~~~~~~~~~~
error: aborting due to 2 previous errors
Run Code Online (Sandbox Code Playgroud)