manager_uncommitted/
main.rs

1use rusty_store::{Storage, StoreManager, Storing};
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Default, Storing)]
5pub struct MyStore {
6    pub count: u32,
7}
8
9pub trait MyStoreTrait {
10    fn increment_count(&mut self);
11}
12
13impl MyStoreTrait for StoreManager<MyStore> {
14    fn increment_count(&mut self) {
15        self.modify_store_uncommitted(|store| store.count += 1)
16    }
17}
18
19fn main() {
20    // Initialize the Storage with the defaults
21    let storage = Storage::new("com.github.mazynoah.storage");
22
23    // Use `StoreManager` to manage the store.
24    let mut manager =
25        StoreManager::new(&storage, "manager_uncommitted").expect("Failed to create StoreManager");
26
27    // Modify the data without saving the changes to disk.
28    manager.increment_count();
29    manager.increment_count();
30    manager.increment_count();
31
32    // Save the data to the storage
33    manager.save().expect("Failed to save count to storage");
34
35    let counter = manager.get_store();
36
37    println!("Count: {}", counter.count);
38}