Skip to content

Commit

Permalink
Rollup merge of #114043 - cathaysia:doc_lazy_lock, r=thomcc
Browse files Browse the repository at this point in the history
docs(LazyLock): add example pass local LazyLock variable to struct
  • Loading branch information
matthiaskrgr authored Jul 25, 2023
2 parents 8ecaf2a + 40dd5a3 commit 91d1d7a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/std/src/sync/lazy_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ union Data<T, F> {
///
/// # Examples
///
/// Initialize static variables with `LazyLock`.
///
/// ```
/// #![feature(lazy_cell)]
///
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 91d1d7a

Please sign in to comment.