Skip to main content

MutexLike

Trait MutexLike 

Source
pub trait MutexLike<T: Send + 'static>: Send + Sync {
    type Guard<'guard>: DerefMut<Target = T> + Send
       where Self: 'guard;

    // Required method
    fn lock(&self) -> impl Future<Output = Self::Guard<'_>> + Send;
}
Expand description

Async mutex shape. The guard type is borrowed so callers can hold the lock across an await without paying a clone. Implementations supply the actual lock primitive — tokio::sync::Mutex<T> for the tokio impl, a per-core single-writer lock for prime.

Required Associated Types§

Source

type Guard<'guard>: DerefMut<Target = T> + Send where Self: 'guard

Required Methods§

Source

fn lock(&self) -> impl Future<Output = Self::Guard<'_>> + Send

Acquire the lock. The returned future resolves when the guard is available; the guard holds the lock until dropped.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§