]> git.proxmox.com Git - rustc.git/blob - vendor/lazy_static-0.2.11/src/core_lazy.rs
New upstream version 1.42.0+dfsg1
[rustc.git] / vendor / lazy_static-0.2.11 / src / core_lazy.rs
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 #[inline(always)]
16 pub const fn new() -> Self {
17 Lazy(Once::new())
18 }
19
20 #[inline(always)]
21 pub fn get<F>(&'static self, builder: F) -> &T
22 where F: FnOnce() -> T
23 {
24 self.0.call_once(builder)
25 }
26 }
27
28 #[macro_export]
29 macro_rules! __lazy_static_create {
30 ($NAME:ident, $T:ty) => {
31 static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::new();
32 }
33 }