manager_uncommitted/
main.rs1use 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 let storage = Storage::new("com.github.mazynoah.storage");
22
23 let mut manager =
25 StoreManager::new(&storage, "manager_uncommitted").expect("Failed to create StoreManager");
26
27 manager.increment_count();
29 manager.increment_count();
30 manager.increment_count();
31
32 manager.save().expect("Failed to save count to storage");
34
35 let counter = manager.get_store();
36
37 println!("Count: {}", counter.count);
38}