Skip to content

Commit

Permalink
docs(LazyLock): add example pass local LazyLock variable to struct
Browse files Browse the repository at this point in the history
Signed-off-by: DragonBillow <[email protected]>
  • Loading branch information
cathaysia committed Jul 25, 2023
1 parent beef07f commit 40dd5a3
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 40dd5a3

Please sign in to comment.