Created
April 17, 2014 22:48
-
-
Save brson/11015838 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static mut my_global_data: Option<MyData> = None; | |
// Do this before launching any threads | |
fn init() { | |
unsafe { my_global_data = Some(load()); } | |
} | |
// The ref this returns isn't actually safe because it could be mutated away. | |
// As long is MyData is deeply immutable though there shouldn't otherwise be a data race here. | |
fn <'a>get_data() -> &'a MyData { | |
unsafe { | |
transmute(my_global_data.as_ref().unwrap()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment