<commit_before>use std::mem;
use std::sync;

pub struct Lazy<T> {
    pub lock: sync::Once,
    pub ptr: *const T,
}

impl<T> Lazy<T> {
    pub fn get<F>(&'static mut self, init: F) -> &'static T
        where F : FnOnce() -> T
    {
        self.lock.call_once(|| {
            unsafe {
                self.ptr = mem::transmute(Box::new(init()));
            }
        });
        unsafe { &*self.ptr }
    }
}

pub const ONCE_INIT: sync::Once = sync::ONCE_INIT;


#[cfg(test)]
mod test {
    use super::{Lazy, ONCE_INIT};<commit_msg>Fix compilation of Lazy#get() on nightly (rustc 1.4.0-nightly (fd230ff12 2015-09-13))<commit_after>use std::mem;
use std::sync;

pub struct Lazy<T> {
    pub lock: sync::Once,
    pub ptr: *const T,
}

impl<T> Lazy<T> {
    pub fn get<F>(&'static mut self, init: F) -> &'static T
        where F : FnOnce() -> T
    {
        // ~ decouple the lifetimes of 'self' and 'self.lock' such we
        // can initialize self.ptr in the call_once closure (note: we
        // do have to initialize self.ptr in the closure to guarantee
        // the ptr is valid for all calling threads at any point in
        // time)
        let lock: &sync::Once = unsafe { mem::transmute(&self.lock) };
        lock.call_once(|| {
            unsafe {
                self.ptr = mem::transmute(Box::new(init()));
            }
        });
        unsafe { &*self.ptr }
    }
}

pub const ONCE_INIT: sync::Once = sync::ONCE_INIT;


#[cfg(test)]
mod test {
    use super::{Lazy, ONCE_INIT};
{'fraction_non_alphanumeric': 0.15415282392026577, 'fraction_numerical': 0.0106312292358804, 'mean_word_length': 2.1974522292993632, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2920364', 'n_tokens_mistral': 538, 'n_tokens_neox': 525, 'n_words': 146}