File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ union Data<T, F> {
25
25
///
26
26
/// # Examples
27
27
///
28
+ /// Initialize static variables with `LazyLock`.
29
+ ///
28
30
/// ```
29
31
/// #![feature(lazy_cell)]
30
32
///
@@ -54,6 +56,24 @@ union Data<T, F> {
54
56
/// // Some("Hoyten")
55
57
/// }
56
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
+
57
77
#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
58
78
pub struct LazyLock < T , F = fn ( ) -> T > {
59
79
once : Once ,
You can’t perform that action at this time.
0 commit comments