rusty_store/lib.rs
1//! # Rusty Store
2//!
3//! RustyStore is a Rust library for managing and storing serialized data using RON (Rusty Object Notation).
4//!
5//! ## Overview
6//!
7//! The library offers a set of utilities for reading, writing, and managing serialized data with RON. The primary components are:
8//!
9//! - `Store`: A store is any struct which implements the Storing trait.
10//! - `Storage`: Manages file system paths for cache, data, and configuration storage.
11//! - `StoreHandle`: Represents a handle to a specific store, allowing access and modification of the data.
12//! - `StoreManager`: Provides an abstraction for managing and modifying store data, including options for committing or deferring changes.
13//!
14//! ## Examples
15//!
16//! ### `examples/minimal`
17//!
18//! ```rust
19//! use rusty_store::{StoreManager, Storage, Storing};
20//! use serde::{Deserialize, Serialize};
21//!
22//! #[derive(Serialize, Deserialize, Default, Storing)]
23//! pub struct MyStore {
24//! pub count: u32,
25//! }
26//!
27//! pub trait MyStoreTrait {
28//! fn increment_count(&mut self) -> Result<(), rusty_store::StoreError>;
29//! }
30//!
31//! impl MyStoreTrait for StoreManager<MyStore> {
32//! fn increment_count(&mut self) -> Result<(), rusty_store::StoreError> {
33//! self.modify_store(|store| store.count += 1)
34//! }
35//! }
36//!
37//!
38//! // Initialize the Storage and create a new manager
39//! let mut counter: StoreManager<MyStore> = Storage::new("com.github.mazynoah.storage")
40//! .new_manager("manager")
41//! .expect("Failed to create StoreManager");
42//!
43//! counter
44//! .increment_count()
45//! .expect("Could not increment count");
46//!
47//! println!("Count: {}", counter.get_store().count);
48//!
49//! ```
50//!
51//! ## Traits
52//!
53//! - **`Storing`**: This trait must be implemented by any type that needs to be stored. It requires the type to be serializable and deserializable using RON, and provides a method to define the type of storage (`Cache`, `Data`, `Config`).
54//!
55
56extern crate rustystore_macros;
57pub use rustystore_macros::Storing;
58mod manager;
59mod storage;
60
61pub use manager::StoreManager;
62pub use storage::*;