1 // Copyright 2016 lazy-static.rs Developers 2 // 3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 // copied, modified, or distributed except according to those terms. 7 8 extern crate spin; 9 10 use self::spin::Once; 11 12 pub struct Lazy<T: Sync>(Once<T>); 13 14 impl<T: Sync> Lazy<T> { 15 pub const INIT: Self = Lazy(Once::INIT); 16 17 #[inline(always)] get<F>(&'static self, builder: F) -> &T where F: FnOnce() -> T18 pub fn get<F>(&'static self, builder: F) -> &T 19 where F: FnOnce() -> T 20 { 21 self.0.call_once(builder) 22 } 23 } 24 25 #[macro_export] 26 #[doc(hidden)] 27 macro_rules! __lazy_static_create { 28 ($NAME:ident, $T:ty) => { 29 static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT; 30 } 31 } 32