Skip to main content

RecordSlot

Struct RecordSlot 

Source
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

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Address an existing application-owned directory. This performs no I/O.

Source

pub fn options(self, options: RecordOptions) -> Self

Publish and read with options instead of the defaults.

Source

pub fn replace(&self, contents: &[u8]) -> Result<()>

Atomically publish while excluding conditional cleanup by older owners.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for RecordSlot

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RecordSlot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.