pub struct StoreCollection<R: Runtime> { /* private fields */ }
Expand description
A collection of stores. This is the core component for store plugins.
Implementations§
Source§impl<R: Runtime> StoreCollection<R>
impl<R: Runtime> StoreCollection<R>
Sourcepub fn builder() -> StoreCollectionBuilder<R>
pub fn builder() -> StoreCollectionBuilder<R>
Builds a new store collection.
Sourcepub fn with_store<F, T>(&self, store_id: impl AsRef<str>, f: F) -> Result<T>
pub fn with_store<F, T>(&self, store_id: impl AsRef<str>, f: F) -> Result<T>
Calls a closure with a mutable reference to the store with the given id.
Sourcepub fn state(&self, store_id: impl AsRef<str>) -> Result<StoreState>
pub fn state(&self, store_id: impl AsRef<str>) -> Result<StoreState>
Gets a clone of the store state.
Sourcepub fn try_state<T>(&self, store_id: impl AsRef<str>) -> Result<T>where
T: DeserializeOwned,
pub fn try_state<T>(&self, store_id: impl AsRef<str>) -> Result<T>where
T: DeserializeOwned,
Gets the store state, then tries to parse it as an instance of type T
.
Sourcepub fn get(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Option<Json>
pub fn get( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, ) -> Option<Json>
Gets a value from a store.
Sourcepub fn try_get<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Result<T>where
T: DeserializeOwned,
pub fn try_get<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Result<T>where
T: DeserializeOwned,
Gets a value from a store and tries to parse it as an instance of type T
.
Sourcepub fn try_get_or<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
default: T,
) -> Twhere
T: DeserializeOwned,
pub fn try_get_or<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
default: T,
) -> Twhere
T: DeserializeOwned,
Gets a value from a store and tries to parse it as an instance of type T
.
If the key does not exist, returns the provided default value.
Sourcepub fn try_get_or_default<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Twhere
T: Default + DeserializeOwned,
pub fn try_get_or_default<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Twhere
T: Default + DeserializeOwned,
Gets a value from a store and tries to parse it as an instance of type T
.
If the key does not exist, returns the default value of T
.
Sourcepub fn try_get_or_else<T, F>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
f: F,
) -> Twhere
T: DeserializeOwned,
F: FnOnce() -> T,
pub fn try_get_or_else<T, F>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
f: F,
) -> Twhere
T: DeserializeOwned,
F: FnOnce() -> T,
Gets a value from a store and tries to parse it as an instance of type T
.
If the key does not exist, returns the result of the provided closure.
Sourcepub fn set<K, V>(
&self,
store_id: impl AsRef<str>,
key: K,
value: V,
) -> Result<()>
pub fn set<K, V>( &self, store_id: impl AsRef<str>, key: K, value: V, ) -> Result<()>
Sets a key-value pair in a store.
Sourcepub fn patch<S>(&self, store_id: impl AsRef<str>, state: S) -> Result<()>where
S: Into<StoreState>,
pub fn patch<S>(&self, store_id: impl AsRef<str>, state: S) -> Result<()>where
S: Into<StoreState>,
Patches a store state.
Sourcepub fn save_now(&self, store_id: impl AsRef<str>) -> Result<()>
pub fn save_now(&self, store_id: impl AsRef<str>) -> Result<()>
Saves a store to the disk immediately, ignoring the save strategy.
Sourcepub fn save_some_now(&self, ids: &[impl AsRef<str>]) -> Result<()>
pub fn save_some_now(&self, ids: &[impl AsRef<str>]) -> Result<()>
Saves some stores to the disk immediately, ignoring the save strategy.
Sourcepub fn save_all_now(&self) -> Result<()>
pub fn save_all_now(&self) -> Result<()>
Saves all the stores to the disk immediately, ignoring the save strategy.
Sourcepub fn default_save_strategy(&self) -> SaveStrategy
pub fn default_save_strategy(&self) -> SaveStrategy
Default save strategy for the stores. This can be overridden on a per-store basis.
Sourcepub fn set_autosave(&self, duration: Duration)
pub fn set_autosave(&self, duration: Duration)
Saves the stores periodically.
Sourcepub fn clear_autosave(&self)
pub fn clear_autosave(&self)
Stops the autosave.
Sourcepub fn watch<F>(&self, store_id: impl AsRef<str>, f: F) -> Result<u32>
pub fn watch<F>(&self, store_id: impl AsRef<str>, f: F) -> Result<u32>
Watches a store for changes.
Sourcepub fn unwatch(
&self,
store_id: impl AsRef<str>,
watcher_id: u32,
) -> Result<bool>
pub fn unwatch( &self, store_id: impl AsRef<str>, watcher_id: u32, ) -> Result<bool>
Removes a watcher from a store.
Sourcepub fn unload_store(&self, id: &str) -> Result<()>
pub fn unload_store(&self, id: &str) -> Result<()>
Removes the store from the collection.