tauri_store/
lib.rs

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