about summary refs log tree commit diff
path: root/library/std/src/sync
diff options
context:
space:
mode:
authorjoboet <jonasboettiger@icloud.com>2023-03-13 16:31:48 +0100
committerjoboet <jonasboettiger@icloud.com>2023-04-27 09:32:28 +0200
commit6776af529a163d5830fea577cf00619940b27908 (patch)
tree07a653969d6e5e2ebe11445ff86798f20ed18fe2 /library/std/src/sync
parent8b8110e1469d459a196f6feb60d82dec48c3cfc2 (diff)
downloadrust-6776af529a163d5830fea577cf00619940b27908.tar.gz
rust-6776af529a163d5830fea577cf00619940b27908.zip
std: use `LazyLock` to lazily resolve backtraces
Diffstat (limited to 'library/std/src/sync')
-rw-r--r--library/std/src/sync/lazy_lock.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs
index a6bc468b092..1fdb7e75c9c 100644
--- a/library/std/src/sync/lazy_lock.rs
+++ b/library/std/src/sync/lazy_lock.rs
@@ -69,6 +69,15 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
         LazyLock { once: Once::new(), data: UnsafeCell::new(Data { f: ManuallyDrop::new(f) }) }
     }
 
+    /// Creates a new lazy value that is already initialized.
+    #[inline]
+    #[cfg(test)]
+    pub(crate) fn preinit(value: T) -> LazyLock<T, F> {
+        let once = Once::new();
+        once.call_once(|| {});
+        LazyLock { once, data: UnsafeCell::new(Data { value: ManuallyDrop::new(value) }) }
+    }
+
     /// Consumes this `LazyLock` returning the stored value.
     ///
     /// Returns `Ok(value)` if `Lazy` is initialized and `Err(f)` otherwise.