"There's a thing I've been..." <- > <@ericseppanen:matrix.org> There's a thing I've been searching for. Something like this: > ```rust > pub struct Ampoule { > taken: AtomicBool, > inner: UnsafeCell, > } > > > impl Ampoule { > /// Mutably access the inner value. > /// > /// This can be done only once. > pub fn break_glass(&'static self) -> Option<&'static mut T> { > let previously_taken = self.taken.swap(true, Ordering::Relaxed); > if previously_taken { > return None; > } > > Some(unsafe { &mut *self.inner.get() }) > } > } > ``` > > Is there a more well-known way of doing this? My requirements are: > - Shouldn't attempt to move T (it contains large memory buffers) > - Doesn't return a guard object that is bound to the &Ampoule (I need to interface with code that expects &'static mut T) That looks a lot like static-cell https://crates.io/crates/static_cell