Struct KeyedLock

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

Source

pub fn new() -> Self

Creates a new KeyedLock.

Source

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.

Source

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