sayiir_persistence/lib.rs
1#![deny(missing_docs)]
2//! Persistence layer for workflow execution state.
3//!
4//! This crate provides traits and implementations for persisting workflow
5//! execution state, enabling distributed execution with checkpoint/restore
6//! capabilities.
7//!
8//! # Trait Hierarchy
9//!
10//! The persistence layer is built around focused sub-traits:
11//!
12//! - **[`SnapshotStore`]**: Core CRUD for workflow snapshots (5 methods).
13//! - **[`SignalStore`]**: Cancel + pause signal primitives with default composite
14//! implementations (3 required + 3 default methods).
15//! - **[`TaskClaimStore`]**: Distributed task claiming (4 methods, opt-in).
16//! - **[`PersistentBackend`]**: Supertrait = `SnapshotStore + SignalStore`,
17//! blanket-implemented so backends never need to impl it directly.
18//!
19//! A minimal backend only needs **8 methods** (`SnapshotStore` + 3 `SignalStore`
20//! primitives) to satisfy `PersistentBackend`.
21//!
22//! # Example
23//!
24//! ```rust,no_run
25//! use sayiir_persistence::{InMemoryBackend, SnapshotStore};
26//! use sayiir_core::snapshot::WorkflowSnapshot;
27//!
28//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
29//! // Create a backend (could be Redis, PostgreSQL, etc.)
30//! let backend = InMemoryBackend::new();
31//!
32//! // Save a snapshot
33//! let snapshot = WorkflowSnapshot::new("instance-123".to_string(), "hash-abc".to_string());
34//! backend.save_snapshot(&snapshot).await?;
35//!
36//! // Load it back
37//! let loaded = backend.load_snapshot("instance-123").await?;
38//! # Ok(())
39//! # }
40//! ```
41
42mod backend;
43mod in_memory;
44
45pub use backend::{BackendError, PersistentBackend, SignalStore, SnapshotStore, TaskClaimStore};
46pub use in_memory::InMemoryBackend;