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 namedSTORE
that is globally accessible.Lazy<Mutex<Store>>
: Uses theLazy
type from theonce_cell
crate to defer the initialization of theStore
instance until it is first accessed. TheMutex
ensures that access to theStore
is thread-safe by allowing only one thread to access it at a time.Lazy::new(|| Mutex::new(Store::new()))
: This line initializes theSTORE
variable using a closure (||
syntax). The closure creates a newMutex
which wraps a new instance ofStore
. TheLazy::new
function ensures that this initialization happens only once, no matter how many timesSTORE
is accessed.
§Example
// Accessing the global STORE instance
let mut store = safina_db::STORE_MUTEX.lock().unwrap();
store.insert("key", "value");