matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.87k stars 109 forks source link

Added get_mut_unchecked #232

Closed dynos01 closed 1 year ago

dynos01 commented 1 year ago

I added get_mut_unchecked() as it might help someone.

Also, there are two things I'm considering but currently unsure about how to correctly implement:

dynos01 commented 1 year ago

For point 2, this does compile, but will it work as expected? (I don't have experience with crate critical-section, and the definitions of borrow and borrow_mut here look different)

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.
    crate::unwrap_unchecked(self.value.borrow_mut().get_mut().get_mut())
}