batpak 0.8.2

Event sourcing with causal graphs and caller-defined gates. Sync API, no async runtime.
Documentation
//! # outbox
//!
//! **Teaches:** typed outbox staging for pre-commit item collection.
//!
//! Run: `cargo run --example outbox`

use batpak::prelude::*;

#[derive(serde::Serialize, serde::Deserialize, EventPayload)]
#[batpak(category = 0xF, type_id = 3)]
struct Tick {
    n: u32,
}

// justifies: INV-EXAMPLES-OBSERVABLE-OUTPUT; example main in examples/outbox.rs prints outbox events to stdout so the reader can see the staging-then-flush observable result.
#[allow(clippy::print_stdout)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let dir = tempfile::tempdir()?;
    let store = Store::open(StoreConfig::new(dir.path()))?;

    let mut outbox = store.outbox();
    outbox.stage(
        Coordinate::new("player:outbox", "room:batch")?,
        Tick::KIND,
        &Tick { n: 1 },
    )?;
    outbox.stage(
        Coordinate::new("player:outbox", "room:batch")?,
        Tick::KIND,
        &Tick { n: 2 },
    )?;
    outbox.stage(
        Coordinate::new("player:outbox", "room:batch")?,
        Tick::KIND,
        &Tick { n: 3 },
    )?;

    let receipts = outbox.flush()?;
    println!(
        "flushed {} staged events through one batch path",
        receipts.len()
    );

    store.close()?;
    Ok(())
}