1 use once_cell::sync::OnceCell;
2 
3 /// Lazily initialized static variable.
4 ///
5 /// Used in generated code.
6 ///
7 /// Currently a wrapper around `once_cell`s `OnceCell`.
8 pub struct Lazy<T> {
9     once_cell: OnceCell<T>,
10 }
11 
12 impl<T> Lazy<T> {
13     /// Uninitialized state.
new() -> Lazy<T>14     pub const fn new() -> Lazy<T> {
15         Lazy {
16             once_cell: OnceCell::new(),
17         }
18     }
19 
20     /// Lazily initialize the value.
get(&self, f: impl FnOnce() -> T) -> &T21     pub fn get(&self, f: impl FnOnce() -> T) -> &T {
22         self.once_cell.get_or_init(f)
23     }
24 }
25