pub struct Store<R, C>where
R: Runtime,
C: CollectionMarker,{ /* private fields */ }Expand description
A key-value store that can persist its state to disk.
Implementations§
Source§impl<R, C> Store<R, C>where
R: Runtime,
C: CollectionMarker,
impl<R, C> Store<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 state(&self) -> &StoreState
pub fn state(&self) -> &StoreState
Gets a reference to the store state.
Sourcepub fn try_state<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
pub fn try_state<T>(&self) -> Result<T, Error>where
T: DeserializeOwned,
Tries to parse the store state as an instance of type T.
Sourcepub fn try_state_or<T>(&self, default: T) -> Twhere
T: DeserializeOwned,
pub fn try_state_or<T>(&self, default: T) -> Twhere
T: DeserializeOwned,
Tries to parse the store state as an instance of type T.
If it cannot be parsed, returns the provided default value.
Sourcepub fn try_state_or_default<T>(&self) -> Twhere
T: DeserializeOwned + Default,
pub fn try_state_or_default<T>(&self) -> Twhere
T: DeserializeOwned + Default,
Tries to parse the store state as an instance of type T.
If it cannot be parsed, returns the default value of T.
Sourcepub fn try_state_or_else<T>(&self, f: impl FnOnce() -> T) -> Twhere
T: DeserializeOwned,
pub fn try_state_or_else<T>(&self, f: impl FnOnce() -> T) -> Twhere
T: DeserializeOwned,
Tries to parse the store state as an instance of type T.
If it cannot be parsed, returns the result of the provided closure.
Sourcepub fn try_get<T>(&self, key: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned,
pub fn try_get<T>(&self, key: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned,
Gets a value from the store and tries to parse it as an instance of type T.
Sourcepub fn try_get_or<T>(&self, key: impl AsRef<str>, default: T) -> Twhere
T: DeserializeOwned,
pub fn try_get_or<T>(&self, key: impl AsRef<str>, default: T) -> Twhere
T: DeserializeOwned,
Gets a value from the 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, key: impl AsRef<str>) -> Twhere
T: DeserializeOwned + Default,
pub fn try_get_or_default<T>(&self, key: impl AsRef<str>) -> Twhere
T: DeserializeOwned + Default,
Gets a value from the 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>(
&self,
key: impl AsRef<str>,
f: impl FnOnce() -> T,
) -> Twhere
T: DeserializeOwned,
pub fn try_get_or_else<T>(
&self,
key: impl AsRef<str>,
f: impl FnOnce() -> T,
) -> Twhere
T: DeserializeOwned,
Gets a value from the 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(
&mut self,
key: impl AsRef<str>,
value: impl Into<Value>,
) -> Result<(), Error>
pub fn set( &mut self, key: impl AsRef<str>, value: impl Into<Value>, ) -> Result<(), Error>
Sets a key-value pair in the store.
Sourcepub fn patch<S>(&mut self, state: S) -> Result<(), Error>where
S: Into<StoreState>,
pub fn patch<S>(&mut self, state: S) -> Result<(), Error>where
S: Into<StoreState>,
Patches the store state.
Sourcepub fn values(&self) -> impl Iterator<Item = &Value>
pub fn values(&self) -> impl Iterator<Item = &Value>
Creates an iterator over the store values.
Sourcepub fn entries(&self) -> impl Iterator<Item = (&String, &Value)>
pub fn entries(&self) -> impl Iterator<Item = (&String, &Value)>
Creates an iterator over the store entries.
Sourcepub fn save_now(&self) -> Result<(), Error>
pub fn save_now(&self) -> Result<(), Error>
Save the store immediately, ignoring the save strategy.
Sourcepub fn save_on_exit(&mut self, enabled: bool)
pub fn save_on_exit(&mut self, enabled: bool)
Whether to save the store on exit. This is enabled by default.
Sourcepub fn save_on_change(&mut self, enabled: bool)
pub fn save_on_change(&mut self, enabled: bool)
Whether to save the store on state change.
Sourcepub fn save_strategy(&self) -> SaveStrategy
pub fn save_strategy(&self) -> SaveStrategy
Current save strategy used by this store.
Sourcepub fn set_save_strategy(&mut self, strategy: SaveStrategy)
pub fn set_save_strategy(&mut self, strategy: SaveStrategy)
Sets the save strategy for this store. Calling this will abort any pending save operation.
Sourcepub fn unwatch(&mut self, id: impl Into<WatcherId>) -> bool
pub fn unwatch(&mut self, id: impl Into<WatcherId>) -> bool
Removes a listener from this store.
Sourcepub fn set_options(&mut self, options: StoreOptions) -> Result<(), Error>
pub fn set_options(&mut self, options: StoreOptions) -> Result<(), Error>
Sets the store options.
Trait Implementations§
Source§impl<R, C> From<&Store<R, C>> for StoreOptionswhere
R: Runtime,
C: CollectionMarker,
impl<R, C> From<&Store<R, C>> for StoreOptionswhere
R: Runtime,
C: CollectionMarker,
Source§fn from(store: &Store<R, C>) -> StoreOptions
fn from(store: &Store<R, C>) -> StoreOptions
Auto Trait Implementations§
impl<R, C> !Freeze for Store<R, C>
impl<R, C> !RefUnwindSafe for Store<R, C>
impl<R, C> Send for Store<R, C>
impl<R, C> Sync for Store<R, C>
impl<R, C> Unpin for Store<R, C>
impl<R, C> !UnwindSafe for Store<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