1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#[cfg(feature = "runtime-tokio")]
pub use tokio::sync::Mutex as AsyncMutex;

#[cfg(feature = "runtime-async-std")]
pub use async_std::sync::Mutex as AsyncMutex;

#[cfg(not(any(feature = "runtime-tokio", feature = "runtime-async-std")))]
mod no_rt_mutex {
    use std::ops::{Deref, DerefMut};

    pub struct AsyncMutex<T> {
        m: std::marker::PhantomData<T>,
    }

    impl<T> AsyncMutex<T> {
        pub fn new(_: T) -> Self {
            Self {
                m: Default::default(),
            }
        }

        pub async fn lock(&self) -> Self {
            Self {
                m: Default::default(),
            }
        }
    }

    impl<T> Deref for AsyncMutex<T> {
        type Target = T;

        fn deref(&self) -> &Self::Target {
            unimplemented!("Please enable a runtime")
        }
    }

    impl<T> DerefMut for AsyncMutex<T> {
        fn deref_mut(&mut self) -> &mut Self::Target {
            unimplemented!("Please enable a runtime")
        }
    }
}

#[cfg(not(any(feature = "runtime-tokio", feature = "runtime-async-std")))]
pub use no_rt_mutex::*;