pub struct LockPrefix<'a> { /* private fields */ }
Expand description

Prefix pattern for lock path creation.

This struct carries path prefix for ephemeral lock path, name filter for candidate contenders and hint to find created lock path in case of Error::ConnectionLoss.

Implementations§

source§

impl<'a> LockPrefix<'a>

source

pub fn new_curator(dir: &'a str, name: &'a str) -> Result<Self, Error>

Apache Curator compatible unique prefix pattern, the final lock path will be {dir}/_c_{uuid}-{name}{ephemeral_sequence}.

Notable lock names
  • latch- for LeaderLatch.
  • lock- for LeaderSelector and InterProcessMutex.
source

pub fn new_shared(prefix: &'a str) -> Result<Self, Error>

Shared path prefix, the final lock path will be {prefix}{ephemeral_sequence}.

CAUTION

All contenders share same prefix, so concurrent contenders must not share same session client. Otherwise, the lock could be ruined in case of Error::ConnectionLoss as there is no way to differentiate contenders using same session.

Notable usages
source

pub fn new_custom(prefix: String, name: &'a str) -> Result<Self, Error>

Custom path prefix, the final lock path will be {prefix}{ephemeral_sequence}.

CAUTION

Don’t reuse same prefix among clients with same session. See LockPrefix::new_shared for details.

API

It is intentional for prefix parameter to be String but not impl Into<String> nor impl Into<Cow<'a, str>>, so to attract attention for best wish.

Notable usages
  • Uses “{dir}/x-{session_id}-” as prefix and “x-” or “” as name for ZooKeeper java client’s WriteLock.

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for LockPrefix<'a>

§

impl<'a> Send for LockPrefix<'a>

§

impl<'a> Sync for LockPrefix<'a>

§

impl<'a> Unpin for LockPrefix<'a>

§

impl<'a> UnwindSafe for LockPrefix<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.