pub struct StoreCollection<R, C>where
R: Runtime,
C: CollectionMarker,{ /* private fields */ }Expand description
A collection of stores. This is the core component for store plugins.
Implementations§
Source§impl<R, C> StoreCollection<R, C>where
R: Runtime,
C: CollectionMarker,
impl<R, C> StoreCollection<R, C>where
R: Runtime,
C: CollectionMarker,
Sourcepub fn app_handle(&self) -> &AppHandle<R>
pub fn app_handle(&self) -> &AppHandle<R>
Gets a handle to the application instance.
Sourcepub fn path_of(&self, store_id: impl AsRef<str>) -> &Path
pub fn path_of(&self, store_id: impl AsRef<str>) -> &Path
Directory where a specific store is saved.
Sourcepub fn with_store<F, T>(
&self,
store_id: impl AsRef<str>,
f: F,
) -> Result<T, Error>
pub fn with_store<F, T>( &self, store_id: impl AsRef<str>, f: F, ) -> Result<T, Error>
Calls a closure with a mutable reference to the store with the given id.
Sourcepub fn raw_state(&self, store_id: impl AsRef<str>) -> Result<StoreState, Error>
pub fn raw_state(&self, store_id: impl AsRef<str>) -> Result<StoreState, Error>
Gets a clone of the raw store state.
Sourcepub fn state<T>(&self, store_id: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned,
pub fn state<T>(&self, store_id: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned,
Gets the store state, then tries to parse it as an instance of type T.
Sourcepub fn state_or<T>(
&self,
store_id: impl AsRef<str>,
default: T,
) -> Result<T, Error>where
T: DeserializeOwned,
pub fn state_or<T>(
&self,
store_id: impl AsRef<str>,
default: T,
) -> Result<T, Error>where
T: DeserializeOwned,
Gets the store state, then tries to parse it as an instance of type T.
If it cannot be parsed, returns the provided default value.
Sourcepub fn state_or_default<T>(&self, store_id: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned + Default,
pub fn state_or_default<T>(&self, store_id: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned + Default,
Gets the store state, then tries to parse it as an instance of type T.
If it cannot be parsed, returns the default value of T.
Sourcepub fn state_or_else<T>(
&self,
store_id: impl AsRef<str>,
f: impl FnOnce() -> T,
) -> Result<T, Error>where
T: DeserializeOwned,
pub fn state_or_else<T>(
&self,
store_id: impl AsRef<str>,
f: impl FnOnce() -> T,
) -> Result<T, Error>where
T: DeserializeOwned,
Gets the store state, then tries to parse it as an instance of type T.
If it cannot be parsed, returns the result of the provided closure.
Sourcepub fn get_raw(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Option<Value>
pub fn get_raw( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, ) -> Option<Value>
Gets a raw value from a store.
Sourcepub unsafe fn get_raw_unchecked(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Value
pub unsafe fn get_raw_unchecked( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, ) -> Value
Gets a raw value from a store.
§Safety
This is undefined behavior if the key doesn’t exist in the store.
Sourcepub fn get<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Result<T, Error>where
T: DeserializeOwned,
pub fn get<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Result<T, Error>where
T: DeserializeOwned,
Gets a value from a store and tries to parse it as an instance of type T.
Sourcepub fn get_or<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
default: T,
) -> Twhere
T: DeserializeOwned,
pub fn 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 get_or_default<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Twhere
T: Default + DeserializeOwned,
pub fn 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 get_or_else<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
f: impl FnOnce() -> T,
) -> Twhere
T: DeserializeOwned,
pub fn get_or_else<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
f: impl FnOnce() -> 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 result of the provided closure.
Sourcepub unsafe fn get_unchecked<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Twhere
T: DeserializeOwned,
pub unsafe fn get_unchecked<T>(
&self,
store_id: impl AsRef<str>,
key: impl AsRef<str>,
) -> Twhere
T: DeserializeOwned,
Gets a value from a store and parses it as an instance of type T.
§Safety
This is undefined behavior if the key doesn’t exist in the store
OR if the value cannot be represented as a valid T.
Sourcepub fn set<K, V>(
&self,
store_id: impl AsRef<str>,
key: K,
value: V,
) -> Result<(), Error>
pub fn set<K, V>( &self, store_id: impl AsRef<str>, key: K, value: V, ) -> Result<(), Error>
Sets a key-value pair in a store.
Sourcepub fn patch<S>(&self, store_id: impl AsRef<str>, state: S) -> Result<(), Error>where
S: Into<StoreState>,
pub fn patch<S>(&self, store_id: impl AsRef<str>, state: S) -> Result<(), Error>where
S: Into<StoreState>,
Patches a store state.
Sourcepub fn save_now(&self, store_id: impl AsRef<str>) -> Result<(), Error>
pub fn save_now(&self, store_id: impl AsRef<str>) -> Result<(), Error>
Saves a store to the disk immediately, ignoring the save strategy.
Sourcepub fn save_some(&self, ids: &[impl AsRef<str>]) -> Result<(), Error>
pub fn save_some(&self, ids: &[impl AsRef<str>]) -> Result<(), Error>
Saves some stores to the disk.
Sourcepub fn save_some_now(&self, ids: &[impl AsRef<str>]) -> Result<(), Error>
pub fn save_some_now(&self, ids: &[impl AsRef<str>]) -> Result<(), Error>
Saves some stores to the disk immediately, ignoring the save strategy.
Sourcepub fn save_all_now(&self) -> Result<(), Error>
pub fn save_all_now(&self) -> Result<(), Error>
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<WatcherId, Error>
pub fn watch<F>( &self, store_id: impl AsRef<str>, f: F, ) -> Result<WatcherId, Error>
Watches a store for changes.
Sourcepub fn unwatch(
&self,
store_id: impl AsRef<str>,
watcher_id: impl Into<WatcherId>,
) -> Result<bool, Error>
pub fn unwatch( &self, store_id: impl AsRef<str>, watcher_id: impl Into<WatcherId>, ) -> Result<bool, Error>
Removes a watcher from a store.
Sourcepub fn allow_save(&self, id: impl AsRef<str>)
pub fn allow_save(&self, id: impl AsRef<str>)
Removes a store from the save denylist.
Sourcepub fn allow_sync(&self, id: impl AsRef<str>)
pub fn allow_sync(&self, id: impl AsRef<str>)
Removes a store from the sync denylist.
Trait Implementations§
Source§impl<R, C> Debug for StoreCollection<R, C>where
R: Runtime,
C: CollectionMarker,
impl<R, C> Debug for StoreCollection<R, C>where
R: Runtime,
C: CollectionMarker,
Auto Trait Implementations§
impl<R, C> !Freeze for StoreCollection<R, C>
impl<R, C> !RefUnwindSafe for StoreCollection<R, C>
impl<R, C> Send for StoreCollection<R, C>
impl<R, C> Sync for StoreCollection<R, C>
impl<R, C> Unpin for StoreCollection<R, C>
impl<R, C> !UnwindSafe for StoreCollection<R, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more