pub struct NicheCell<T>(UnsafeCell<Option<T>>);Expand description
A datatype with interior mutability, which can be uninitialized via [Option].
This datatype is designed to be used with values that can take advantage of niche
optimization (where the datatype T has a value which is guaranteed to be invalid, like
a NonZeroU64 being zero)
The caller may also use this datatype if [Option] instead of MaybeUninit
is necessary for code safety, as this type returns [None] on calling
Self::get if Self::init has not been run yet, compared to UncheckedCell
where calling UncheckedCell::get before UncheckedCell::init is undefined behavior.
Tuple Fields§
§0: UnsafeCell<Option<T>>Implementations§
Source§impl<T> NicheCell<T>
impl<T> NicheCell<T>
Sourcepub unsafe fn init(&self, value: T)
pub unsafe fn init(&self, value: T)
Set the inner value
§Safety
The caller must guarantee the following:
- That this method has never been called before and will never be called again
- That at the time of calling this method, no references or pointers to this data exist
- While this method is being called, no other CPU is working with the given data