Skip to content

Instantly share code, notes, and snippets.

@Kimundi
Last active August 29, 2015 13:55
Show Gist options
  • Save Kimundi/8781753 to your computer and use it in GitHub Desktop.
Save Kimundi/8781753 to your computer and use it in GitHub Desktop.
lazy_init! {
static ref map: T = new_T();
}
=>
static map: lazy1::Lazy = lazy1::Lazy;
mod lazy1 {
static mut map: *T = 0 as *T;
struct Lazy;
impl Lazy {
fn get(&self) -> &'static T {
do_locked(|| {
if map == 0 {
map = ~new_T() as *T;
}
map as &'static T
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment