"This is what I currently am..." <- > <@davidcole1340:matrix.org> This is what I currently am doing > > ```rs > fn main() { > // ... > > GLOBAL_STATE.lock(|s| s.borrow_mut().replace(my_t)); > } > > static GLOBAL_STATE: blocking_mutex::CriticalSectionMutex>> = ...; > > #[interrupt] > fn PIO0_IRQ_0() { > static mut INTERNAL_STATE: Option<&'static mut T> = None; > > let internal_state = INTERNAL_STATE.get_or_insert_with(|| GLOBAL_STATE.lock(|cell| cell.borrow_mut().take().unwrap())); > > // internal_state.... > } > ``` > > but it feels a bit dirty, so hoping someone has a better way haha Gotcha! Yeah - basically I'm not sure how to do it better than that in "safe" + "userspace" code, if that makes sense? You can definitely write unsafe code with a safe API to allow something like this, for example I wrote the `cmim` crate a while back to specifically do this: https://docs.rs/cmim/latest/cmim/ It *looks* like a mutex, but there's no actual expensive locking, instead it looks at which ISR vector is active, and only allows one ISR to access the data, or you can disable the ISR to "move out" of the mutex. I wouldn't recommend that crate anymore, it's kinda old, but maybe that demonstrates how you can use unsafe to say "look I know it works like X, so I can make a safe API around that"