From 6cdaa319598cad17c90cb19f7bbae5125ca7385d Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 3 Oct 2024 10:17:47 +0800 Subject: [PATCH] Add store function --- plugins/store/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/store/src/lib.rs b/plugins/store/src/lib.rs index a4fd20e9..532ee1ab 100644 --- a/plugins/store/src/lib.rs +++ b/plugins/store/src/lib.rs @@ -165,12 +165,22 @@ async fn save(app: AppHandle, rid: ResourceId) -> Result<()> { } pub trait StoreExt { + /// Create a store or get an existing store with default settings at path + fn store(&self, path: impl AsRef) -> Arc>; + /// Create a store with default settings fn create_store(&self, path: impl AsRef) -> Result>>; + /// Get a store builder fn store_builder(&self, path: impl AsRef) -> StoreBuilder; + /// Get an existing store fn get_store(&self, path: impl AsRef) -> Option>>; } impl> StoreExt for T { + fn store(&self, path: impl AsRef) -> Arc> { + self.create_store(&path) + .unwrap_or_else(|_| self.get_store(path).unwrap()) + } + fn create_store(&self, path: impl AsRef) -> Result>> { StoreBuilder::new(self.app_handle(), path).build() }