pub struct KeyedLock<K: Eq + Hash + Clone + Send>(/* private fields */);Expand description
A lock that provides mutually exclusive access to a resource, where the resource is identified by a key.
Implementations§
Source§impl<K: Eq + Hash + Clone + Send> KeyedLock<K>
impl<K: Eq + Hash + Clone + Send> KeyedLock<K>
Sourcepub async fn lock<'a>(&'a self, key: K) -> Guard<'a, K>
pub async fn lock<'a>(&'a self, key: K) -> Guard<'a, K>
Acquires a lock for a given key.
If the lock is already held by another task, this method will wait until the lock is released.
When the returned Guard is dropped, the lock is released.
Sourcepub async fn lock_owned(self: &Arc<Self>, key: K) -> OwnedGuard<K>
pub async fn lock_owned(self: &Arc<Self>, key: K) -> OwnedGuard<K>
Acquires a lock for a given key, returning an OwnedGuard.
This method is for use with Arc<KeyedLock>. If the lock is already
held by another task, this method will wait until the lock is released.
When the returned OwnedGuard is dropped, the lock is released.
Auto Trait Implementations§
impl<K> !Freeze for KeyedLock<K>
impl<K> !RefUnwindSafe for KeyedLock<K>
impl<K> Send for KeyedLock<K>
impl<K> Sync for KeyedLock<K>
impl<K> Unpin for KeyedLock<K>where
K: Unpin,
impl<K> !UnwindSafe for KeyedLock<K>
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