Skip to content

Commit

Permalink
Explain safety of unsync::OnceCell::get(&self) in more detail
Browse files Browse the repository at this point in the history
  • Loading branch information
Enselic committed Jan 2, 2023
1 parent af9d29c commit cc07949
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ pub mod unsync {
/// Returns `None` if the cell is empty.
#[inline]
pub fn get(&self) -> Option<&T> {
// Safe due to `inner`'s invariant
// Safe due to `inner`'s invariant of being written to at most once.
// Had multiple writes to `inner` been allowed, a reference to the
// value we return now would become dangling by a write of a
// different value later.
unsafe { &*self.inner.get() }.as_ref()
}

Expand Down

0 comments on commit cc07949

Please sign in to comment.