mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-28 21:51:47 +02:00
Add store function
This commit is contained in:
1 file changed
+10
@@ -165,12 +165,22 @@ async fn save<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait StoreExt<R: Runtime> {
|
pub trait StoreExt<R: Runtime> {
|
||||||
|
/// Create a store or get an existing store with default settings at path
|
||||||
|
fn store(&self, path: impl AsRef<Path>) -> Arc<Store<R>>;
|
||||||
|
/// Create a store with default settings
|
||||||
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>>;
|
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>>;
|
||||||
|
/// Get a store builder
|
||||||
fn store_builder(&self, path: impl AsRef<Path>) -> StoreBuilder<R>;
|
fn store_builder(&self, path: impl AsRef<Path>) -> StoreBuilder<R>;
|
||||||
|
/// Get an existing store
|
||||||
fn get_store(&self, path: impl AsRef<Path>) -> Option<Arc<Store<R>>>;
|
fn get_store(&self, path: impl AsRef<Path>) -> Option<Arc<Store<R>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
|
impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
|
||||||
|
fn store(&self, path: impl AsRef<Path>) -> Arc<Store<R>> {
|
||||||
|
self.create_store(&path)
|
||||||
|
.unwrap_or_else(|_| self.get_store(path).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
|
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
|
||||||
StoreBuilder::new(self.app_handle(), path).build()
|
StoreBuilder::new(self.app_handle(), path).build()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user