Hi all! I’m not sure is it an error or "static mut" variables misunderstanding
from my side. The source:
struct MyStruct {
val: int
}
static mut global_data: Option<~MyStruct> = None;
fn test_call() {
unsafe {
match global_data {
Some(data) => { println!("We have data {:?}", data);}
None => { println!("We don't have data");}
}
}
}
fn main() {
unsafe {
global_data = Some(~MyStruct{val: 42});
}
test_call();
test_call();
}
and output:
We have data ~MyStruct{val: 42}
We don't have data
But if I’m changing global_data from Option<~MyStruct> to Option<MyStruct>
output is changed also:
We have data ~MyStruct{val: 42}
We have data ~MyStruct{val: 42}
Is it normal behaviour and owning pointers cannot be stored in global variables
or an error?_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev