pub struct PersistentProducerNonce { /* private fields */ }Expand description
Persistent u64 nonce loaded from (or created at) a stable path.
Callers construct via Self::load_or_create and read the value
via Self::nonce. The struct itself is cheap to clone — the
nonce is a u64 and the path is a PathBuf retained for
debugging / logging.
Implementations§
Source§impl PersistentProducerNonce
impl PersistentProducerNonce
Sourcepub fn load_or_create(path: impl AsRef<Path>) -> Result<Self>
pub fn load_or_create(path: impl AsRef<Path>) -> Result<Self>
Load (or create) the persistent nonce at path.
On first call: samples a fresh u64 from getrandom, writes
it to path atomically (write to <path>.tmp, fsync, rename
to path), and returns the value.
On subsequent calls (post-restart, same path): reads the existing 8-byte file and returns its little-endian u64.
Errors:
io::ErrorKind::NotFoundif the parent directory doesn’t exist. We don’t auto-create the parent — that’s a configuration decision the caller should make explicitly.io::ErrorKind::InvalidDataif the file exists but has length other than 8 bytes (corrupt or someone else’s file at this path).- Other
io::Errorfrom filesystem operations.
Trait Implementations§
Source§impl Clone for PersistentProducerNonce
impl Clone for PersistentProducerNonce
Source§fn clone(&self) -> PersistentProducerNonce
fn clone(&self) -> PersistentProducerNonce
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PersistentProducerNonce
impl RefUnwindSafe for PersistentProducerNonce
impl Send for PersistentProducerNonce
impl Sync for PersistentProducerNonce
impl Unpin for PersistentProducerNonce
impl UnsafeUnpin for PersistentProducerNonce
impl UnwindSafe for PersistentProducerNonce
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more