macro_rules! lazy_static {
($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
lazy_static!(PRIV, $(#[$attr])* static ref $N : $T = $e; $($t)*);
};
($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
lazy_static!(PUB, $(#[$attr])* static ref $N : $T = $e; $($t)*);
};
($VIS:ident, $(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {
lazy_static!(MAKE TY, $VIS, $(#[$attr])*, $N);
impl ::std::ops::Deref for $N {
type Target = $T;
fn deref<'a>(&'a self) -> &'a $T {
#[inline(always)]
fn __static_ref_initialize() -> Box<$T> { Box::new($e) }
unsafe {
use std::sync::{Once, ONCE_INIT};
use std::mem::transmute;
#[inline(always)]
fn require_sync<T: Sync>(_: &T) { }
static mut DATA: *const $T = 0 as *const $T;
static mut ONCE: Once = ONCE_INIT;
ONCE.call_once(|| {
DATA = transmute::<Box<$T>, *const $T>(__static_ref_initialize());
});
let static_ref = &*DATA;
require_sync(static_ref);
static_ref
}
}
}
lazy_static!($($t)*);
};
(MAKE TY, PUB, $(#[$attr:meta])*, $N:ident) => {
#[allow(missing_copy_implementations)]
#[allow(non_camel_case_types)]
#[allow(dead_code)]
$(#[$attr])*
pub struct $N {__private_field: ()}
#[doc(hidden)]
pub static $N: $N = $N {__private_field: ()};
};
(MAKE TY, PRIV, $(#[$attr:meta])*, $N:ident) => {
#[allow(missing_copy_implementations)]
#[allow(non_camel_case_types)]
#[allow(dead_code)]
$(#[$attr])*
struct $N {__private_field: ()}
#[doc(hidden)]
static $N: $N = $N {__private_field: ()};
};
() => ()
}