pub struct RecordSlot(/* private fields */);Expand description
A discovery slot whose publishers and conditional cleanup share a lock. Use the same slot path in every generation. Lock files remain persistent.
Implementations§
Source§impl RecordSlot
impl RecordSlot
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Address an existing application-owned directory. This performs no I/O.
Sourcepub fn options(self, options: RecordOptions) -> Self
pub fn options(self, options: RecordOptions) -> Self
Publish and read with options instead of the defaults.
Sourcepub fn replace(&self, contents: &[u8]) -> Result<()>
pub fn replace(&self, contents: &[u8]) -> Result<()>
Atomically publish while excluding conditional cleanup by older owners.
Sourcepub fn repair(&self, contents: &[u8]) -> Result<bool>
pub fn repair(&self, contents: &[u8]) -> Result<bool>
Restore an owned record only if its contents differ. The caller must still be authorized to advertise this endpoint; a lock does not elect it.
Sourcepub fn replace_if(
&self,
contents: &[u8],
replace: impl FnOnce(Option<&[u8]>) -> bool,
) -> Result<bool>
pub fn replace_if( &self, contents: &[u8], replace: impl FnOnce(Option<&[u8]>) -> bool, ) -> Result<bool>
Publish contents only if replace accepts the current record, or
None when there is none. The record is read and the predicate runs
under the slot lock, so no other slot user changes it in between.
True if published.
Sourcepub fn remove_if_matches(&self, contents: &[u8]) -> Result<bool>
pub fn remove_if_matches(&self, contents: &[u8]) -> Result<bool>
Remove only the exact record still belonging to this owner. A successor’s publication cannot race between the comparison and unlink.
Sourcepub fn remove_if(&self, remove: impl FnOnce(&[u8]) -> bool) -> Result<bool>
pub fn remove_if(&self, remove: impl FnOnce(&[u8]) -> bool) -> Result<bool>
Remove the record only if remove accepts its contents, under the
slot lock. A missing record is false, without calling the predicate.
Sourcepub fn read(&self) -> Result<Option<Vec<u8>>>
pub fn read(&self) -> Result<Option<Vec<u8>>>
Read the record without the slot lock: publication is atomic, so this
sees one complete version. None when there is none. A record that
is not a regular file, a symlink included, or that is longer than the
read limit is InvalidData.
On Windows an open that races a replacement can be refused, or find
no record while the rename is in progress. A refused open is retried a
few times. A missing record is waited for, up to 2 s, while a
temporary file of this record created in the last 10 s shows a
publication in progress; otherwise it is None at once.