tauri_store/store/
options.rs1use crate::CollectionMarker;
2
3use super::save::SaveStrategy;
4use super::Store;
5use serde::{Deserialize, Serialize};
6use tauri::Runtime;
7
8#[non_exhaustive]
10#[derive(Clone, Debug, Default, Deserialize, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct StoreOptions {
13 pub save_on_exit: Option<bool>,
14 pub save_on_change: Option<bool>,
15 pub save_strategy: Option<SaveStrategy>,
16}
17
18impl<R, C> From<&Store<R, C>> for StoreOptions
19where
20 R: Runtime,
21 C: CollectionMarker,
22{
23 fn from(store: &Store<R, C>) -> Self {
24 Self {
25 save_on_exit: Some(store.save_on_exit),
26 save_on_change: Some(store.save_on_change),
27 save_strategy: store.save_strategy,
28 }
29 }
30}
31
32#[allow(clippy::needless_pass_by_value)]
33pub(super) fn set_options<R, C>(store: &mut Store<R, C>, options: StoreOptions)
34where
35 R: Runtime,
36 C: CollectionMarker,
37{
38 if let Some(enabled) = options.save_on_exit {
39 store.save_on_exit = enabled;
40 }
41
42 if let Some(enabled) = options.save_on_change {
43 store.save_on_change = enabled;
44 }
45
46 if let Some(strategy) = options.save_strategy {
47 store.set_save_strategy(strategy);
48 }
49}