Skip to content

Commit 91d1d7a

Browse files
authored
Rollup merge of #114043 - cathaysia:doc_lazy_lock, r=thomcc
docs(LazyLock): add example pass local LazyLock variable to struct
2 parents 8ecaf2a + 40dd5a3 commit 91d1d7a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

library/std/src/sync/lazy_lock.rs

+20
Original file line numberDiff line numberDiff 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")]
5878
pub struct LazyLock<T, F = fn() -> T> {
5979
once: Once,

0 commit comments

Comments
 (0)