pub struct ProvenanceLog { /* private fields */ }Expand description
Append-only writer with in-process serialization.
Implementations§
Source§impl ProvenanceLog
impl ProvenanceLog
Sourcepub fn open(
path: impl Into<Utf8PathBuf>,
session_id: String,
) -> Result<Self, LogError>
pub fn open( path: impl Into<Utf8PathBuf>, session_id: String, ) -> Result<Self, LogError>
Open or create the log at path, stamping every row with
session_id.
session_id MUST be a 26-char ULID generated once per process
invocation by the caller. Re-opening the log within the same process
reuses the same session_id; re-opening in a new process gets a new
one. This crate intentionally does NOT generate the ULID itself —
callers are responsible for creating one (e.g. via the ulid crate
already present in the workspace) and threading it through.
If the file exists, scan it once to recover the last ts_seq and
this_hash. If the file is missing or empty, the first row will use
prev_hash = "GENESIS" and ts_seq = 1.
§Errors
Returns LogError::Io for I/O failures or if any line fails to
parse as a LogRow (synthetic message: "corrupted log at line N: …").
The writer never silently truncates a corrupt log.
Returns LogError::NotARegularFile if path exists but is not a
regular file (e.g. a directory).
Sourcepub fn append(&self, input: RowInput<'_>) -> Result<u64, LogError>
pub fn append(&self, input: RowInput<'_>) -> Result<u64, LogError>
Append a row. Computes prev_hash, ts_seq, ts, session_id, and
this_hash; the caller only supplies the semantic fields via
RowInput.
Returns the assigned ts_seq on success.
§Errors
Returns LogError on serialization, I/O, or fsync failure. Callers
MUST treat this as fail-closed and abort the surrounding fetch.
Sourcepub fn path(&self) -> &Utf8Path
pub fn path(&self) -> &Utf8Path
Returns the path the log was opened at. Useful for tests and audit tooling.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Returns the session id stamped into every row written through this writer.