tauri_store/
lib.rs

1#![doc = include_str!("../README.md")]
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3
4mod collection;
5mod error;
6mod event;
7mod manager;
8mod meta;
9pub mod prelude;
10mod store;
11
12#[cfg(feature = "plugin")]
13mod command;
14#[cfg(feature = "plugin")]
15mod plugin;
16
17pub use collection::{OnLoadFn, StoreCollection};
18pub use error::{BoxResult, Error, Result};
19pub use manager::ManagerExt;
20pub use serde_json::Value as Json;
21pub use store::{SaveStrategy, Store, StoreId, StoreOptions, StoreState, WatcherId};
22
23pub use event::{
24  EventSource, STORE_CONFIG_CHANGE_EVENT, STORE_STATE_CHANGE_EVENT, STORE_UNLOAD_EVENT,
25};
26
27#[cfg(feature = "plugin")]
28pub use plugin::{init, Builder};
29
30#[cfg(feature = "derive")]
31pub use tauri_store_macros::{Collection, CollectionBuilder};
32
33use tauri::{Manager, Runtime};
34
35/// Calls a closure with a mutable reference to the store with the given id.
36pub fn with_store<R, M, F, T>(manager: &M, id: impl AsRef<str>, f: F) -> Result<T>
37where
38  R: Runtime,
39  M: Manager<R> + ManagerExt<R>,
40  F: FnOnce(&mut Store<R>) -> T,
41{
42  manager.store_collection().with_store(id, f)
43}