Debian Codegraph @

debian/missing-sources/lazy_static/src/core_lazy.rs

raw
1 // Copyright 2016 lazy-static.rs Developers
2 //
3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4 // https://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5 // https://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)]
18 pub fn get<F>(&'static self, builder: F) -> &T
19 where
20 F: FnOnce() -> T,
21 {
22 self.0.call_once(builder)
23 }
24 }
25
26 #[macro_export]
27 #[doc(hidden)]
28 macro_rules! __lazy_static_create {
29 ($NAME:ident, $T:ty) => {
30 static $NAME: $crate::lazy::Lazy<$T> = $crate::lazy::Lazy::INIT;
31 };
32 }