diff options
| author | bors <bors@rust-lang.org> | 2023-07-25 18:58:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-25 18:58:30 +0000 |
| commit | 18fa7b9104aad0cbaba6d9aff8e19d6b96eedcef (patch) | |
| tree | 6b74f079ab3642d1caa9c38920de1f0e5ddab37b /library/std | |
| parent | 8327047b23dc1eb150fdfb42177939388661eb6d (diff) | |
| parent | ba6982b8a00e08f859479d16c776c0d9693e8937 (diff) | |
| download | rust-18fa7b9104aad0cbaba6d9aff8e19d6b96eedcef.tar.gz rust-18fa7b9104aad0cbaba6d9aff8e19d6b96eedcef.zip | |
Auto merge of #114063 - matthiaskrgr:rollup-c90czu6, r=matthiaskrgr
Rollup of 7 pull requests
Successful merges:
- #114008 (coverage: Obtain the `__llvm_covfun` section name outside a per-function loop)
- #114014 (builtin_macros: expect raw strings too)
- #114043 (docs(LazyLock): add example pass local LazyLock variable to struct)
- #114051 (Add regression test for invalid "unused const" in method)
- #114052 (Suggest `{Option,Result}::as_ref()` instead of `cloned()` in some cases)
- #114058 (Add help for crate arg when crate name is invalid)
- #114060 (abi: unsized field in union - assert to delay bug )
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/sync/lazy_lock.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs index a6bc468b092..37bdec5abcc 100644 --- a/library/std/src/sync/lazy_lock.rs +++ b/library/std/src/sync/lazy_lock.rs @@ -25,6 +25,8 @@ union Data<T, F> { /// /// # Examples /// +/// Initialize static variables with `LazyLock`. +/// /// ``` /// #![feature(lazy_cell)] /// @@ -54,6 +56,24 @@ union Data<T, F> { /// // Some("Hoyten") /// } /// ``` +/// Initialize fields with `LazyLock`. +/// ``` +/// #![feature(lazy_cell)] +/// +/// use std::sync::LazyLock; +/// +/// #[derive(Debug)] +/// struct UseCellLock { +/// number: LazyLock<u32>, +/// } +/// fn main() { +/// let lock: LazyLock<u32> = LazyLock::new(|| 0u32); +/// +/// let data = UseCellLock { number: lock }; +/// println!("{}", *data.number); +/// } +/// ``` + #[unstable(feature = "lazy_cell", issue = "109736")] pub struct LazyLock<T, F = fn() -> T> { once: Once, |
