pub struct StoreBuilder<R: Runtime> { /* private fields */ }
Expand description
Builds a Store
Implementations§
Source§impl<R: Runtime> StoreBuilder<R>
impl<R: Runtime> StoreBuilder<R>
Sourcepub fn new<M: Manager<R>, P: AsRef<Path>>(manager: &M, path: P) -> Self
pub fn new<M: Manager<R>, P: AsRef<Path>>(manager: &M, path: P) -> Self
Creates a new StoreBuilder
.
§Examples
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let builder = tauri_plugin_store::StoreBuilder::new(app, "store.bin");
Ok(())
});
Sourcepub fn defaults(self, defaults: HashMap<String, JsonValue>) -> Self
pub fn defaults(self, defaults: HashMap<String, JsonValue>) -> Self
Inserts a default key-value pair.
§Examples
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let mut defaults = std::collections::HashMap::new();
defaults.insert("foo".to_string(), "bar".into());
let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
.defaults(defaults)
.build()?;
Ok(())
});
Sourcepub fn default(
self,
key: impl Into<String>,
value: impl Into<JsonValue>,
) -> Self
pub fn default( self, key: impl Into<String>, value: impl Into<JsonValue>, ) -> Self
Inserts multiple default key-value pairs.
§Examples
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = tauri_plugin_store::StoreBuilder::new(app, "store.bin")
.default("foo".to_string(), "bar")
.build()?;
Ok(())
});
Sourcepub fn serialize(self, serialize: SerializeFn) -> Self
pub fn serialize(self, serialize: SerializeFn) -> Self
Defines a custom serialization function.
§Examples
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
.serialize(|cache| serde_json::to_vec(&cache).map_err(Into::into))
.build()?;
Ok(())
});
Sourcepub fn deserialize(self, deserialize: DeserializeFn) -> Self
pub fn deserialize(self, deserialize: DeserializeFn) -> Self
Defines a custom deserialization function
§Examples
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
.deserialize(|bytes| serde_json::from_slice(&bytes).map_err(Into::into))
.build()?;
Ok(())
});
Sourcepub fn auto_save(self, debounce_duration: Duration) -> Self
pub fn auto_save(self, debounce_duration: Duration) -> Self
Auto save on modified with a debounce duration
§Examples
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = tauri_plugin_store::StoreBuilder::new(app, "store.json")
.auto_save(std::time::Duration::from_millis(100))
.build()?;
Ok(())
});
Sourcepub fn disable_auto_save(self) -> Self
pub fn disable_auto_save(self) -> Self
Disable auto save on modified with a debounce duration.
Sourcepub fn create_new(self) -> Self
pub fn create_new(self) -> Self
Force create a new store with default values even if it already exists.
Sourcepub fn override_defaults(self) -> Self
pub fn override_defaults(self) -> Self
Override the store values when creating the store, ignoring defaults.
Sourcepub fn build(self) -> Result<Arc<Store<R>>>
pub fn build(self) -> Result<Arc<Store<R>>>
Load the existing store with the same path or creates a new Store
.
If a store with the same path has already been loaded its instance is returned.
§Examples
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = tauri_plugin_store::StoreBuilder::new(app, "store.json").build();
Ok(())
});
Auto Trait Implementations§
impl<R> Freeze for StoreBuilder<R>
impl<R> !RefUnwindSafe for StoreBuilder<R>
impl<R> Send for StoreBuilder<R>
impl<R> Sync for StoreBuilder<R>
impl<R> Unpin for StoreBuilder<R>
impl<R> !UnwindSafe for StoreBuilder<R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more