manager_trait/
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) -> Result<(), rusty_store::StoreError>;
11}
12
13impl MyStoreTrait for StoreManager<MyStore> {
14    fn increment_count(&mut self) -> Result<(), rusty_store::StoreError> {
15        self.modify_store(|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_trait").expect("Failed to create StoreManager");
26
27    // Modify and save the data using `StoreManager`.
28    manager
29        .increment_count()
30        .expect("Failed to increment count");
31
32    let counter = manager.get_store();
33
34    println!("Count: {}", counter.count);
35}