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> {
2525///
2626/// # Examples
2727///
28+ /// Initialize static variables with `LazyLock`.
29+ ///
2830/// ```
2931/// #![feature(lazy_cell)]
3032///
@@ -54,6 +56,24 @@ union Data<T, F> {
5456/// // Some("Hoyten")
5557/// }
5658/// ```
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+
5777#[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
5878pub struct LazyLock < T , F = fn ( ) -> T > {
5979 once : Once ,
You can’t perform that action at this time.
0 commit comments