Struct StoreCollection

Source
pub struct StoreCollection<R>
where R: Runtime,
{ /* private fields */ }
Expand description

A collection of stores. This is the core component for store plugins.

Implementations§

Source§

impl<R> StoreCollection<R>
where R: Runtime,

Source

pub fn builder() -> StoreCollectionBuilder<R>

Builds a new store collection.

Source

pub fn ids(&self) -> Vec<StoreId>

Lists all the store ids.

Source

pub fn path(&self) -> PathBuf

Directory where the stores are saved.

Source

pub fn set_path(&self, path: impl AsRef<Path>) -> Result<(), Error>

Sets the directory where the stores are saved. This will move all currently active stores to the new directory.

Source

pub fn with_store<F, T>( &self, store_id: impl AsRef<str>, f: F, ) -> Result<T, Error>
where F: FnOnce(&mut Store<R>) -> T,

Calls a closure with a mutable reference to the store with the given id.

Source

pub fn state(&self, store_id: impl AsRef<str>) -> Result<StoreState, Error>

Gets a clone of the store state.

Source

pub fn try_state<T>(&self, store_id: impl AsRef<str>) -> Result<T, Error>

Gets the store state, then tries to parse it as an instance of type T.

Source

pub fn get( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, ) -> Option<Value>

Gets a value from a store.

Source

pub fn try_get<T>( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, ) -> Result<T, Error>

Gets a value from a store and tries to parse it as an instance of type T.

Source

pub fn try_get_or<T>( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, default: T, ) -> 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 provided default value.

Source

pub fn try_get_or_default<T>( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, ) -> 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 default value of T.

Source

pub fn try_get_or_else<T>( &self, store_id: impl AsRef<str>, key: impl AsRef<str>, f: impl FnOnce() -> T, ) -> 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.

Source

pub fn set<K, V>( &self, store_id: impl AsRef<str>, key: K, value: V, ) -> Result<(), Error>
where K: AsRef<str>, V: Into<Value>,

Sets a key-value pair in a store.

Source

pub fn patch<S>(&self, store_id: impl AsRef<str>, state: S) -> Result<(), Error>
where S: Into<StoreState>,

Patches a store state.

Source

pub fn save(&self, store_id: impl AsRef<str>) -> Result<(), Error>

Saves a store to the disk.

Source

pub fn save_now(&self, store_id: impl AsRef<str>) -> Result<(), Error>

Saves a store to the disk immediately, ignoring the save strategy.

Source

pub fn save_some(&self, ids: &[impl AsRef<str>]) -> Result<(), Error>

Saves some stores to the disk.

Source

pub fn save_some_now(&self, ids: &[impl AsRef<str>]) -> Result<(), Error>

Saves some stores to the disk immediately, ignoring the save strategy.

Source

pub fn save_all(&self) -> Result<(), Error>

Saves all the stores to the disk.

Source

pub fn save_all_now(&self) -> Result<(), Error>

Saves all the stores to the disk immediately, ignoring the save strategy.

Source

pub fn default_save_strategy(&self) -> SaveStrategy

Default save strategy for the stores. This can be overridden on a per-store basis.

Source

pub fn set_autosave(&self, duration: Duration)

Saves the stores periodically.

Source

pub fn clear_autosave(&self)

Stops the autosave.

Source

pub fn watch<F>( &self, store_id: impl AsRef<str>, f: F, ) -> Result<WatcherId, Error>
where F: Fn(AppHandle<R>) -> Result<(), Error> + Send + Sync + 'static,

Watches a store for changes.

Source

pub fn unwatch( &self, store_id: impl AsRef<str>, watcher_id: impl Into<WatcherId>, ) -> Result<bool, Error>

Removes a watcher from a store.

Trait Implementations§

Source§

impl<R> Debug for StoreCollection<R>
where R: Runtime,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<R> Resource for StoreCollection<R>
where R: Runtime,

Source§

fn name(&self) -> Cow<'_, str>

Returns a string representation of the resource. The default implementation returns the Rust type name, but specific resource types may override this trait method.
Source§

fn close(self: Arc<Self>)

Resources may implement the close() trait method if they need to do resource specific clean-ups, such as cancelling pending futures, after a resource has been removed from the resource table.

Auto Trait Implementations§

§

impl<R> !Freeze for StoreCollection<R>

§

impl<R> !RefUnwindSafe for StoreCollection<R>

§

impl<R> Send for StoreCollection<R>

§

impl<R> Sync for StoreCollection<R>

§

impl<R> Unpin for StoreCollection<R>

§

impl<R> !UnwindSafe for StoreCollection<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T