diff options
| author | Mahmoud Al-Qudsi <mqudsi@neosmart.net> | 2024-05-24 12:10:05 -0500 |
|---|---|---|
| committer | Mahmoud Al-Qudsi <mqudsi@neosmart.net> | 2024-05-24 12:15:06 -0500 |
| commit | 65dffc1990f91b470f23175ef243bdd5e0b5313a (patch) | |
| tree | 7d0463d5bf1437129b21be88ba99de3300c742e0 /library/std/src/sync | |
| parent | 213ad10c8f0fc275648552366275dc4e07f97462 (diff) | |
| download | rust-65dffc1990f91b470f23175ef243bdd5e0b5313a.tar.gz rust-65dffc1990f91b470f23175ef243bdd5e0b5313a.zip | |
Change pedantically incorrect OnceCell/OnceLock wording
While the semantic intent of a OnceCell/OnceLock is that it can only be written to once (upon init), the fact of the matter is that both these types offer a `take(&mut self) -> Option<T>` mechanism that, when successful, resets the cell to its initial state, thereby technically allowing it to be written to again. Despite the fact that this can only happen with a mutable reference (generally only used during the construction of the OnceCell/OnceLock), it would be incorrect to say that the type itself as a whole categorically prevents being initialized or written to more than once (since it is possible to imagine an identical type only without the `take()` method that actually fulfills that contract). To clarify, change "that cannot be.." to "that nominally cannot.." and add a note to OnceCell about what can be done with an `&mut Self` reference.
Diffstat (limited to 'library/std/src/sync')
| -rw-r--r-- | library/std/src/sync/once_lock.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index fc830bacced..6b9f70da854 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -5,7 +5,7 @@ use crate::mem::MaybeUninit; use crate::panic::{RefUnwindSafe, UnwindSafe}; use crate::sync::Once; -/// A synchronization primitive which can be written to only once. +/// A synchronization primitive which can nominally be written to only once. /// /// This type is a thread-safe [`OnceCell`], and can be used in statics. /// |
