Struct LockManager

Source
pub struct LockManager<K: Eq + Hash + Clone> { /* private fields */ }
Expand description

A thread-safe lock manager that provides key-based locking capabilities.

The LockManager allows concurrent access control based on keys of type K. It supports both single-key and batch locking operations.

Type parameter:

  • K: The key type that must implement Eq + Hash + Clone traits

Implementations§

Source§

impl<K: Eq + Hash + Clone> LockManager<K>

Source

pub fn new() -> Self

Creates a new LockManager instance with default capacity.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new LockManager with the specified capacity.

§Arguments
  • capacity - The initial capacity for the internal map
Source

pub fn with_capacity_and_shard_amount( capacity: usize, shard_amount: usize, ) -> Self

Creates a new LockManager with specified capacity and shard amount.

§Arguments
  • capacity - The initial capacity for the internal map
  • shard_amount - The number of shards to use for internal concurrency
Source

pub fn lock<'a, 'b>(&'a self, key: &'b K) -> LockGuard<'a, 'b, K>

Acquires a lock for a single key.

This method will block until the lock can be acquired.

§Arguments
  • key - The key to lock
§Returns

Returns a LockGuard that will automatically release the lock when dropped

Source

pub fn batch_lock<'a, 'b>( &'a self, keys: &'b BTreeSet<K>, ) -> BatchLockGuard<'a, 'b, K>

Acquires locks for multiple keys atomically.

This method will block until all locks can be acquired. The locks are acquired in a consistent order to prevent deadlocks.

§Arguments
  • keys - A BTreeSet containing the keys to lock
§Returns

Returns a BatchLockGuard that will automatically release all locks when dropped

Trait Implementations§

Source§

impl<K: Eq + Hash + Clone> Default for LockManager<K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K> Freeze for LockManager<K>

§

impl<K> !RefUnwindSafe for LockManager<K>

§

impl<K> Send for LockManager<K>
where K: Send,

§

impl<K> Sync for LockManager<K>
where K: Send + Sync,

§

impl<K> Unpin for LockManager<K>

§

impl<K> UnwindSafe for LockManager<K>
where K: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 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.