pub struct Ledger<E> { /* private fields */ }Expand description
Append-only JSONL ledger with per-day file rotation.
Generic over the event type E. For multi-writer scenarios,
wrap in Arc<Mutex<Ledger<E>>> — the file-level flock is
handled by the OS when opening for append.
Implementations§
Source§impl<E: Serialize + DeserializeOwned> Ledger<E>
impl<E: Serialize + DeserializeOwned> Ledger<E>
Sourcepub fn append(&mut self, event: &E) -> Result<()>
pub fn append(&mut self, event: &E) -> Result<()>
Append one event to today’s JSONL file. Debounced fsync (≤1s).
pub fn base_dir(&self) -> &Path
pub fn flush(&mut self) -> Result<()>
Sourcepub fn scan_days(base_dir: &Path, days: u32) -> Vec<Result<E>> ⓘ
pub fn scan_days(base_dir: &Path, days: u32) -> Vec<Result<E>> ⓘ
Scan the most recent days daily files in chronological order.
Skips malformed lines and missing files.
Sourcepub fn scan_since(base_dir: &Path, since: Option<NaiveDate>) -> DayScan<E>
pub fn scan_since(base_dir: &Path, since: Option<NaiveDate>) -> DayScan<E>
Scan every daily file dated since or later (all of them when None),
oldest first, tagging each event with its file’s day.
Unlike Self::scan_days the window is not tied to today, so a reader
that must not lose old records (trash expiry, #2174) can resume from a
day it chose. Files not named YYYY-MM-DD.jsonl and malformed lines are
skipped. Read failures are NOT silent: the result says which days could
not be read in full and whether the directory listing itself failed, so
a caller that checkpoints progress can tell a complete replay from one
that missed records (review #2176 P2).