Skip to main content

Crate eventfold

Crate eventfold 

Source
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) -> State that 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§

AppendConflict
Conflict details when a conditional append fails.
AppendResult
Result of a successful append operation.
Event
An immutable event record stored in the log.
EventLog
An append-only event log backed by files in a single directory.
EventLogBuilder
Builder for configuring and opening an EventLog.
EventReader
Cheap, cloneable reader for an event log.
EventWriter
Exclusive writer for a single event log file.
View
A derived view over an event log.

Enums§

ConditionalAppendError
Error type for conditional append operations.
LockMode
Controls file locking behavior for an EventWriter.
WaitResult
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§

ReduceFn
A pure function that folds an event into state.