custom_location/
main.rs

1use rusty_store::{Storage, StoreManager, Storing};
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Default)]
5pub struct MyStore {
6    pub count: u32,
7}
8
9impl Storing for MyStore {
10    fn store_type() -> rusty_store::StoringType {
11        rusty_store::StoringType::Custom("./app_data_folder/stores/".into())
12    }
13}
14
15impl MyStore {
16    fn increment_count(&mut self) {
17        self.count += 1;
18    }
19}
20
21fn main() {
22    // Initialize the Storage with the defaults
23    let storage = Storage::new("com.github.mazynoah.storage");
24
25    // Create a StoreManager for managing the store data
26    let mut counter_manager = storage
27        .new_manager::<MyStore>("custom_location")
28        .expect("Failed to create StoreManager");
29
30    // Alternatively:
31    let mut counter_manager = StoreManager::<MyStore>::new(&storage, "custom_location")
32        .expect("Failed to create StoreManager");
33
34    // Get a mutable reference to the store
35    let counter = counter_manager.get_store_mut();
36
37    counter.count = 75;
38    counter.increment_count();
39
40    // Save the data to the storage
41    counter_manager
42        .save()
43        .expect("Failed to save count to storage");
44
45    let counter = counter_manager.get_store();
46
47    println!("Count: {}", counter.count);
48}