pub trait StoreExt<R: Runtime> {
// Required methods
fn store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>>;
fn store_builder(&self, path: impl AsRef<Path>) -> StoreBuilder<R>;
fn get_store(&self, path: impl AsRef<Path>) -> Option<Arc<Store<R>>>;
}Required Methods§
Sourcefn store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>>
fn store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>>
Create a store or load an existing store with default settings at the given path.
If the store is already loaded, its instance is automatically returned.
§Examples
use tauri_plugin_store::StoreExt;
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = app.store("my-store")?;
Ok(())
});Sourcefn store_builder(&self, path: impl AsRef<Path>) -> StoreBuilder<R>
fn store_builder(&self, path: impl AsRef<Path>) -> StoreBuilder<R>
Get a store builder.
The builder can be used to configure the store.
To use the default settings see Self::store.
§Examples
use tauri_plugin_store::StoreExt;
use std::time::Duration;
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = app.store_builder("users.json").auto_save(Duration::from_secs(1)).build()?;
Ok(())
});Sourcefn get_store(&self, path: impl AsRef<Path>) -> Option<Arc<Store<R>>>
fn get_store(&self, path: impl AsRef<Path>) -> Option<Arc<Store<R>>>
Get a handle of an already loaded store.
If the store is not loaded or does not exist, it returns None.
Note that using this function can cause race conditions if you fallback to creating or loading the store,
so you should consider using Self::store if you are not sure if the store is loaded or not.
§Examples
use tauri_plugin_store::StoreExt;
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = if let Some(s) = app.get_store("store.json") {
s
} else {
// this is not thread safe; if another thread is doing the same load/create,
// there will be a race condition; in this case we could remove the get_store
// and only run app.store() as it will return the existing store if it has been loaded
app.store("store.json")?
};
Ok(())
});Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.