Struct Store

Source
pub struct Store<R, C>{ /* private fields */ }
Expand description

A key-value store that can persist its state to disk.

Implementations§

Source§

impl<R, C> Store<R, C>

Source

pub fn id(&self) -> StoreId

The id of the store.

Source

pub fn path(&self) -> PathBuf

Path to the store file.

Source

pub fn app_handle(&self) -> &AppHandle<R>

Gets a handle to the application instance.

Source

pub fn state(&self) -> &StoreState

Gets a reference to the store state.

Source

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

Tries to parse the store state as an instance of type T.

Source

pub fn try_state_or<T>(&self, default: T) -> T

Tries to parse the store state as an instance of type T.

If it cannot be parsed, returns the provided default value.

Source

pub fn try_state_or_default<T>(&self) -> T

Tries to parse the store state as an instance of type T.

If it cannot be parsed, returns the default value of T.

Source

pub fn try_state_or_else<T>(&self, f: impl FnOnce() -> T) -> T

Tries to parse the store state as an instance of type T.

If it cannot be parsed, returns the result of the provided closure.

Source

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

Gets a value from the store.

Source

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

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

Source

pub fn try_get_or<T>(&self, key: impl AsRef<str>, default: T) -> T

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.

Source

pub fn try_get_or_default<T>(&self, key: impl AsRef<str>) -> T

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.

Source

pub fn try_get_or_else<T>( &self, key: impl AsRef<str>, f: impl FnOnce() -> T, ) -> T

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.

Source

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

Sets a key-value pair in the store.

Source

pub fn patch<S>(&mut self, state: S) -> Result<(), Error>
where S: Into<StoreState>,

Patches the store state.

Source

pub fn has(&self, key: impl AsRef<str>) -> bool

Whether the store has a key.

Source

pub fn keys(&self) -> impl Iterator<Item = &String>

Creates an iterator over the store keys.

Source

pub fn values(&self) -> impl Iterator<Item = &Value>

Creates an iterator over the store values.

Source

pub fn entries(&self) -> impl Iterator<Item = (&String, &Value)>

Creates an iterator over the store entries.

Source

pub fn len(&self) -> usize

Returns the amount of items in the store.

Source

pub fn is_empty(&self) -> bool

Whether the store is empty.

Source

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

Save the store state to the disk.

Source

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

Save the store immediately, ignoring the save strategy.

Source

pub fn save_on_exit(&mut self, enabled: bool)

Whether to save the store on exit. This is enabled by default.

Source

pub fn save_on_change(&mut self, enabled: bool)

Whether to save the store on state change.

Source

pub fn save_strategy(&self) -> SaveStrategy

Current save strategy used by this store.

Source

pub fn set_save_strategy(&mut self, strategy: SaveStrategy)

Sets the save strategy for this store. Calling this will abort any pending save operation.

Source

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

Watches the store for changes.

Source

pub fn unwatch(&mut self, id: impl Into<WatcherId>) -> bool

Removes a listener from this store.

Source

pub fn set_options(&mut self, options: StoreOptions) -> Result<(), Error>

Sets the store options.

Trait Implementations§

Source§

impl<R, C> Debug for Store<R, C>

Source§

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

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

impl<R, C> From<&Store<R, C>> for StoreOptions

Source§

fn from(store: &Store<R, C>) -> StoreOptions

Converts to this type from the input type.

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> 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,