Trait Mutex

Source
pub trait Mutex: Sized {
    // Required methods
    fn new() -> Option<Self>;
    fn lock(&self) -> MutexGuard<'_, Self>;
    fn try_lock(&self) -> Option<MutexGuard<'_, Self>>;
    fn unlock(&self, token: GuardToken);
}
Expand description

Describes Mutex interface

Required Methods§

Source

fn new() -> Option<Self>

Creates new instance

Returns if Semaphore is successfully created.

Source

fn lock(&self) -> MutexGuard<'_, Self>

Acquires lock, returning guard that unlocks self on drop.

If lock is already acquired, it blocks until mutex is unlocked

Source

fn try_lock(&self) -> Option<MutexGuard<'_, Self>>

Attempts to acquire lock, returning guard that unlocks self on drop.

If lock is already acquired, it returns None

Source

fn unlock(&self, token: GuardToken)

Tells how to perform unlock.

Method implementation should be safe, but is allowed to mis-behave when invoked without prior lock

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Semaphore> Mutex for Mutex<T>