Skip to main content

rabia_persistence/
lib.rs

1//! # Rabia Persistence
2//!
3//! Simple persistence implementations for the Rabia consensus protocol.
4//!
5//! This crate provides simplified persistence implementations that store
6//! exactly one state value, matching Rabia's consensus requirements.
7//!
8//! ## Implementations
9//!
10//! - [`InMemoryPersistence`] - State stored in memory (testing/non-persistent)
11//! - [`FileSystemPersistence`] - State stored in a file (persistent across restarts)
12//!
13//! ## Example
14//!
15//! ```rust
16//! use rabia_persistence::{InMemoryPersistence, FileSystemPersistence};
17//! use rabia_core::persistence::PersistenceLayer;
18//!
19//! # tokio_test::block_on(async {
20//! // In-memory persistence
21//! let persistence = InMemoryPersistence::new();
22//! persistence.save_state(b"hello world").await.unwrap();
23//! let state = persistence.load_state().await.unwrap();
24//! assert_eq!(state, Some(b"hello world".to_vec()));
25//!
26//! // File-based persistence  
27//! let fs_persistence = FileSystemPersistence::new("/tmp/rabia-test").await.unwrap();
28//! fs_persistence.save_state(b"persistent state").await.unwrap();
29//! let state = fs_persistence.load_state().await.unwrap();
30//! assert_eq!(state, Some(b"persistent state".to_vec()));
31//! # });
32//! ```
33
34pub mod file_system;
35pub mod in_memory;
36mod tests;
37
38pub use file_system::FileSystemPersistence;
39pub use in_memory::InMemoryPersistence;