Expand description
§eventfold
Your application state is a fold over an event log.
eventfold is a lightweight, append-only event log with derived views for Rust. You define events as JSON, write pure reducer functions to fold them into state, and let the library handle persistence, snapshots, and log rotation. No database, no infrastructure — just files in a directory.
§Quick Start
use eventfold::{Event, EventLog};
use serde::{Serialize, Deserialize};
use serde_json::json;
#[derive(Default, Clone, Serialize, Deserialize)]
struct Counter { count: u64 }
fn count_reducer(mut state: Counter, _event: &Event) -> Counter {
state.count += 1;
state
}
let mut log = EventLog::builder(dir.path())
.view::<Counter>("counter", count_reducer)
.open()?;
log.append(&Event::new("click", json!({"x": 10})))?;
log.refresh_all()?;
let state: &Counter = log.view("counter")?;
assert_eq!(state.count, 1);§Core Concepts
- Events are immutable JSON records appended to a log file (
app.jsonl). - Reducers are pure functions
fn(State, &Event) -> Statethat fold events into application state. - Views are derived state computed by applying a reducer to the event log, with snapshots on disk for incremental performance.
See docs/guide.md for a detailed concepts guide.
Re-exports§
pub use snapshot::Snapshot;
Modules§
- snapshot
- Snapshot persistence for derived view state.
Structs§
- Append
Conflict - Conflict details when a conditional append fails.
- Append
Result - Result of a successful append operation.
- Event
- An immutable event record stored in the log.
- Event
Log - An append-only event log backed by files in a single directory.
- Event
LogBuilder - Builder for configuring and opening an
EventLog. - Event
Reader - Cheap, cloneable reader for an event log.
- Event
Writer - Exclusive writer for a single event log file.
- View
- A derived view over an event log.
Enums§
- Conditional
Append Error - Error type for conditional append operations.
- Lock
Mode - Controls file locking behavior for an
EventWriter. - Wait
Result - Result of waiting for new events.
Traits§
- ViewOps
- Trait for type-erased view operations during log rotation.
Functions§
- line_
hash - Compute xxh64 hash of raw line bytes (without trailing newline), hex-encoded.
Type Aliases§
- Reduce
Fn - A pure function that folds an event into state.