We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 8ecaf2a + 40dd5a3 commit 91d1d7aCopy full SHA for 91d1d7a
library/std/src/sync/lazy_lock.rs
@@ -25,6 +25,8 @@ union Data<T, F> {
25
///
26
/// # Examples
27
28
+/// Initialize static variables with `LazyLock`.
29
+///
30
/// ```
31
/// #![feature(lazy_cell)]
32
@@ -54,6 +56,24 @@ union Data<T, F> {
54
56
/// // Some("Hoyten")
55
57
/// }
58
59
+/// Initialize fields with `LazyLock`.
60
+/// ```
61
+/// #![feature(lazy_cell)]
62
63
+/// use std::sync::LazyLock;
64
65
+/// #[derive(Debug)]
66
+/// struct UseCellLock {
67
+/// number: LazyLock<u32>,
68
+/// }
69
+/// fn main() {
70
+/// let lock: LazyLock<u32> = LazyLock::new(|| 0u32);
71
72
+/// let data = UseCellLock { number: lock };
73
+/// println!("{}", *data.number);
74
75
76
+
77
#[unstable(feature = "lazy_cell", issue = "109736")]
78
pub struct LazyLock<T, F = fn() -> T> {
79
once: Once,
0 commit comments