File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 133133//! - [`Mutex`]: Mutual Exclusion mechanism, which ensures that at
134134//! most one thread at a time is able to access some data.
135135//!
136- //! - [`Once`]: Used for a thread-safe, one-time global initialization routine
136+ //! - [`Once`]: Used for a thread-safe, one-time global initialization routine.
137+ //! Mostly useful for implementing other types like `OnceLock`.
137138//!
138139//! - [`OnceLock`]: Used for thread-safe, one-time initialization of a
139140//! variable, with potentially different initializers based on the caller.
Original file line number Diff line number Diff line change @@ -10,9 +10,15 @@ use crate::fmt;
1010use crate :: panic:: { RefUnwindSafe , UnwindSafe } ;
1111use crate :: sys:: sync as sys;
1212
13- /// A synchronization primitive which can be used to run a one-time global
14- /// initialization. Useful for one-time initialization for FFI or related
15- /// functionality. This type can only be constructed with [`Once::new()`].
13+ /// A low-level synchronization primitive for one-time global execution.
14+ ///
15+ /// Previously this was the only "execute once" synchronization in `std`.
16+ /// Other libraries implemented novel synchronizing types with `Once`, like
17+ /// [`OnceLock<T>`] or [`LazyLock<T, F>`], before those were added to `std`.
18+ /// `OnceLock<T>` in particular supersedes `Once` in functionality and should
19+ /// be preferred for the common case where the `Once` is associated with data.
20+ ///
21+ /// This type can only be constructed with [`Once::new()`].
1622///
1723/// # Examples
1824///
@@ -25,6 +31,9 @@ use crate::sys::sync as sys;
2531/// // run initialization here
2632/// });
2733/// ```
34+ ///
35+ /// [`OnceLock<T>`]: crate::sync::OnceLock
36+ /// [`LazyLock<T, F>`]: crate::sync::LazyLock
2837#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2938pub struct Once {
3039 inner : sys:: Once ,
You can’t perform that action at this time.
0 commit comments