pub struct FileSeq { /* private fields */ }Expand description
File-backed sequence counter that survives restarts, including power loss.
Each write goes to a sibling temp file that is fsync’d, atomically renamed over the target,
and (on Unix) followed by an fsync of the parent directory so the rename itself is durable.
This matters because the counter is a fiscal anti-replay guard — a value that silently reverted
after a crash would re-issue a sequence number the device already saw (rejected as
BadSequenceNumber).
The file’s content is a single decimal integer (UTF-8, optionally followed by whitespace).
On open, missing files initialise to 0; corrupted contents are surfaced as
io::ErrorKind::InvalidData rather than silently reset.
This is not safe to share between processes. The crate does not take an OS-level file lock. Consumers running multiple processes against the same counter file must coordinate externally.