hermes_runtime_components/traits/
mutex.rs

1use core::ops::DerefMut;
2
3use cgp::prelude::*;
4
5#[derive_component(MutexComponent, ProvideMutex<Runtime>)]
6#[async_trait]
7pub trait HasMutex: Async {
8    type Mutex<T: Async>: Async;
9
10    type MutexGuard<'a, T: Async>: 'a + Send + Sync + DerefMut<Target = T>;
11
12    fn new_mutex<T: Async>(item: T) -> Self::Mutex<T>;
13
14    async fn acquire_mutex<'a, T: Async>(mutex: &'a Self::Mutex<T>) -> Self::MutexGuard<'a, T>;
15}
16
17pub type MutexOf<Runtime, T> = <Runtime as HasMutex>::Mutex<T>;
18
19pub type MutexGuardOf<'a, Runtime, T> = <Runtime as HasMutex>::MutexGuard<'a, T>;