Static safina_db::STORE_MUTEX
source · pub static STORE_MUTEX: Lazy<Mutex<Store>>Expand description
A globally accessible, thread-safe, lazily initialized instance of Store.
§Details
static STORE: Declares a static variable namedSTOREthat is globally accessible.Lazy<Mutex<Store>>: Uses theLazytype from theonce_cellcrate to defer the initialization of theStoreinstance until it is first accessed. TheMutexensures that access to theStoreis thread-safe by allowing only one thread to access it at a time.Lazy::new(|| Mutex::new(Store::new())): This line initializes theSTOREvariable using a closure (||syntax). The closure creates a newMutexwhich wraps a new instance ofStore. TheLazy::newfunction ensures that this initialization happens only once, no matter how many timesSTOREis accessed.
§Example
// Accessing the global STORE instance
let mut store = safina_db::STORE_MUTEX.lock().unwrap();
store.insert("key", "value");