pub struct Mutex<T: ?Sized> { /* private fields */ }
Expand description
The simple Mutex, which will provide unique access to you data between multiple threads/futures.
Implementations§
Source§impl<T: ?Sized> Mutex<T>
impl<T: ?Sized> Mutex<T>
Sourcepub const fn lock(&self) -> MutexGuardFuture<'_, T> ⓘ
pub const fn lock(&self) -> MutexGuardFuture<'_, T> ⓘ
Acquires the mutex.
Returns a guard that releases the mutex and wake the next locker when dropped.
§Examples
use fast_async_mutex::mutex::Mutex;
#[tokio::main]
async fn main() {
let mutex = Mutex::new(10);
let guard = mutex.lock().await;
assert_eq!(*guard, 10);
}
Sourcepub fn lock_owned(self: &Arc<Self>) -> MutexOwnedGuardFuture<T> ⓘ
pub fn lock_owned(self: &Arc<Self>) -> MutexOwnedGuardFuture<T> ⓘ
Acquires the mutex.
Returns a guard that releases the mutex and wake the next locker when dropped.
MutexOwnedGuardFuture
have a 'static
lifetime, but requires the Arc<Mutex<T>>
type
§Examples
use fast_async_mutex::mutex::Mutex;
use std::sync::Arc;
#[tokio::main]
async fn main() {
let mutex = Arc::new(Mutex::new(10));
let guard = mutex.lock_owned().await;
assert_eq!(*guard, 10);
}
Trait Implementations§
impl<T> Send for Mutex<T>
impl<T> Sync for Mutex<T>
Auto Trait Implementations§
impl<T> !Freeze for Mutex<T>
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Unpin for Mutex<T>
impl<T> UnwindSafe for Mutex<T>where
T: UnwindSafe + ?Sized,
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