pub struct Store<R: Runtime> { /* private fields */ }Expand description
A key-value store, persisted to a file resolved with resolve_store_path.
The values are kept in memory and written to disk on Store::save, and also automatically
after each modification unless auto save has been disabled with
StoreBuilder::disable_auto_save. Any pending auto save is applied when the store is dropped.
Create or load one with StoreExt::store or StoreBuilder.
It is a Resource, so it is also reachable from the frontend by its ResourceId;
closing that resource unregisters the store, meaning the next load creates a new instance.
Implementations§
Source§impl<R: Runtime> Store<R>
impl<R: Runtime> Store<R>
Sourcepub fn set(&self, key: impl Into<String>, value: impl Into<JsonValue>)
pub fn set(&self, key: impl Into<String>, value: impl Into<JsonValue>)
Inserts a key-value pair into the store.
Sourcepub fn get(&self, key: impl AsRef<str>) -> Option<JsonValue>
pub fn get(&self, key: impl AsRef<str>) -> Option<JsonValue>
Returns the value for the given key or None if the key does not exist.
Sourcepub fn has(&self, key: impl AsRef<str>) -> bool
pub fn has(&self, key: impl AsRef<str>) -> bool
Returns true if the given key exists in the store.
Sourcepub fn clear(&self)
pub fn clear(&self)
Clears the store, removing all key-value pairs.
Note: To clear the storage and reset it to its default value, use reset instead.
Sourcepub fn reset(&self)
pub fn reset(&self)
Resets the store to its default value.
If no default value has been set, this method behaves identical to clear.
Sourcepub fn entries(&self) -> Vec<(String, JsonValue)>
pub fn entries(&self) -> Vec<(String, JsonValue)>
Returns a list of all key-value pairs in the store.
Sourcepub fn reload(&self) -> Result<()>
pub fn reload(&self) -> Result<()>
Update the store from the on-disk state
Note:
- This method loads the data and merges it with the current store,
this behavior will be changed to resetting to default first and then merging with the on-disk state in v3,
to fully match the store with the on-disk state,
use
reload_ignore_defaultsinstead - This method does not emit change events
Sourcepub fn reload_ignore_defaults(&self) -> Result<()>
pub fn reload_ignore_defaults(&self) -> Result<()>
Load the store from the on-disk state, ignoring defaults
Note: This method does not emit change events
Sourcepub fn close_resource(&self)
pub fn close_resource(&self)
Removes the store from the resource table