pub mod interface { pub trait Mutex { type Data; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R; } } use core::cell::UnsafeCell; pub struct NullLock where T: ?Sized { data: UnsafeCell, } unsafe impl Send for NullLock where T: ?Sized + Send {} unsafe impl Sync for NullLock where T: ?Sized + Send {} impl NullLock { pub const fn new(data: T) -> Self { Self { data: UnsafeCell::new(data), } } } impl interface::Mutex for NullLock { type Data = T; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut T) -> R) -> R { let data = unsafe { &mut *self.data.get() }; f(data) } }