manager/
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
9impl MyStore {
10    fn increment_count(&mut self) {
11        self.count += 1;
12    }
13}
14
15fn main() {
16    // Initialize the Storage with the defaults
17    let storage = Storage::new("com.github.mazynoah.storage");
18
19    // Create a StoreManager for managing the store data
20    let mut counter_manager = storage
21        .new_manager::<MyStore>("manager")
22        .expect("Failed to create StoreManager");
23
24    // Alternatively:
25    let mut counter_manager =
26        StoreManager::<MyStore>::new(&storage, "manager").expect("Failed to create StoreManager");
27
28    // Get a mutable reference to the store
29    let counter = counter_manager.get_store_mut();
30
31    counter.count = 75;
32    counter.increment_count();
33
34    // Save the data to the storage
35    counter_manager
36        .save()
37        .expect("Failed to save count to storage");
38
39    let counter = counter_manager.get_store();
40
41    println!("Count: {}", counter.count);
42}