Skip to content

Commit

Permalink
Added get_mut_unchecked for all feature selections
Browse files Browse the repository at this point in the history
  • Loading branch information
dynos01 committed Jun 5, 2023
1 parent e2a1e21 commit 919e4ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/imp_cs.rs
Expand Up @@ -66,6 +66,19 @@ impl<T> OnceCell<T> {
crate::unwrap_unchecked(self.value.borrow(CriticalSection::new()).get())
}

/// Gets the mutable reference to the underlying value, without checking if the cell
/// is initialized.
///
/// # Safety
///
/// Caller must ensure that the cell is in initialized state, and that
/// the contents are acquired by (synchronized to) this thread.
pub(crate) unsafe fn get_mut_unchecked(&mut self) -> &mut T {
debug_assert!(self.is_initialized());
// SAFETY: The caller ensures that the value is initialized and access synchronized.
self.get_mut().unwrap_unchecked()
}

#[inline]
pub(crate) fn get_mut(&mut self) -> Option<&mut T> {
self.value.get_mut().get_mut()
Expand Down
1 change: 0 additions & 1 deletion src/imp_std.rs
Expand Up @@ -119,7 +119,6 @@ impl<T> OnceCell<T> {
///
/// Caller must ensure that the cell is in initialized state, and that
/// the contents are acquired by (synchronized to) this thread.
#[cfg(not(feature = "critical_section"))]
pub(crate) unsafe fn get_mut_unchecked(&mut self) -> &mut T {
debug_assert!(self.is_initialized());
let slot = &mut *self.value.get();
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Expand Up @@ -1039,7 +1039,6 @@ pub mod sync {
/// Caller must ensure that the cell is in initialized state, and that
/// the contents are acquired by (synchronized to) this thread.
#[inline]
#[cfg(not(feature = "critical_section"))]
pub unsafe fn get_mut_unchecked(&mut self) -> &mut T {
self.0.get_mut_unchecked()
}
Expand Down

0 comments on commit 919e4ae

Please sign in to comment.