mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rollup merge of #114043 - cathaysia:doc_lazy_lock, r=thomcc
docs(LazyLock): add example pass local LazyLock variable to struct
This commit is contained in:
commit
91d1d7aa44
@ -25,6 +25,8 @@ union Data<T, F> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Initialize static variables with `LazyLock`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(lazy_cell)]
|
||||
///
|
||||
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user