Expand description
Minimal snapshot store for durable state managers.
minisnap provides a simple, reliable way to serialize and restore a full copy
of application state to/from disk. It is designed to complement WAL-based systems
like [ministore] and [ministate] by enabling fast recovery and future WAL compaction.
§Features
- Explicit snapshotting: You control when snapshots are created.
- Atomic writes: Snapshots are written to a temp file and atomically renamed.
- Sequence tracking: Each snapshot is associated with a logical sequence number (e.g., the last applied WAL index) for consistency.
- File-based recovery: Each snapshot is saved as a separate numbered file so the latest completed snapshot can be restored without requiring a separate sequence metadata file.
§Integration
Intended for use with ministate (via the snapshot feature), but can be used standalone.
§Example
use minisnap::{
SnapStore,
codec::json::JsonCodec,
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)]
struct AppState { counter: u64 }
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tmp = tempfile::tempdir()?;
let store = SnapStore::new(tmp.path(), JsonCodec);
let state = AppState { counter: 42 };
store.create(state.clone(), 10).await?; // seq = 10
let (restored, seq) = store.restore::<AppState>().await?;
assert_eq!(restored, state);
assert_eq!(seq, 10);
Ok(())
}Re-exports§
pub use crate::codec::json::JsonCodec;pub use crate::codec::Codec;pub use crate::error::MiniSnapError;pub use crate::error::Result;
Modules§
- codec
- Codec trait and codec implementations for snapshot serialization.
Structs§
- Snap
Store - Manages snapshot storage in a dedicated directory.
Enums§
- Mini
Snap Error - Errors returned by
minisnapoperations.