diff options
| author | joboet <jonasboettiger@icloud.com> | 2023-03-13 16:31:48 +0100 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2023-04-27 09:32:28 +0200 |
| commit | 6776af529a163d5830fea577cf00619940b27908 (patch) | |
| tree | 07a653969d6e5e2ebe11445ff86798f20ed18fe2 /library/std/src/sync | |
| parent | 8b8110e1469d459a196f6feb60d82dec48c3cfc2 (diff) | |
| download | rust-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.rs | 9 |
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. |
