We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
unsync::OnceCell::get(&self)
1 parent af9d29c commit cc07949Copy full SHA for cc07949
src/lib.rs
@@ -454,7 +454,10 @@ pub mod unsync {
454
/// Returns `None` if the cell is empty.
455
#[inline]
456
pub fn get(&self) -> Option<&T> {
457
- // Safe due to `inner`'s invariant
+ // Safe due to `inner`'s invariant of being written to at most once.
458
+ // Had multiple writes to `inner` been allowed, a reference to the
459
+ // value we return now would become dangling by a write of a
460
+ // different value later.
461
unsafe { &*self.inner.get() }.as_ref()
462
}
463
0 commit comments