Crate minisnap

Crate minisnap 

Source
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.
  • Human-readable: Snapshots are stored as plain JSON (via serde).

§Integration

Intended for use with ministate (via the snapshot feature), but can be used standalone.

§Example

use minisnap::SnapStore;
use serde::{Deserialize, Serialize};

#[derive(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());

    let state = AppState { counter: 42 };
    store.create(&state, 10).await?; // seq = 10

    let (restored, seq) = store.restore().await?;
    let restored: AppState = restored;
    assert_eq!(restored, state);
    assert_eq!(seq, 10);
    Ok(())
}

Structs§

SnapStore
Manages snapshot storage in a dedicated directory.

Enums§

MiniSnapError
Error type for minisnap operations.

Type Aliases§

Result
A specialized Result type for minisnap operations.