[][src]Struct async_lock::Lock

pub struct Lock<T>(_);

An async lock.

Implementations

impl<T> Lock<T>[src]

pub fn new(data: T) -> Lock<T>[src]

Creates a new async lock.

Examples

use async_lock::Lock;

let lock = Lock::new(0);

pub async fn lock<'_>(&'_ self) -> LockGuard<T>[src]

Acquires the lock.

Returns a guard that releases the lock when dropped.

Examples

use async_lock::Lock;

let lock = Lock::new(10);
let guard = lock.lock().await;
assert_eq!(*guard, 10);

pub async fn lock_slow<'_>(&'_ self) -> LockGuard<T>[src]

Slow path for acquiring the lock.

pub fn try_lock(&self) -> Option<LockGuard<T>>[src]

Attempts to acquire the lock.

If the lock could not be acquired at this time, then None is returned. Otherwise, a guard is returned that releases the lock when dropped.

Examples

use async_lock::Lock;

let lock = Lock::new(10);
if let Some(guard) = lock.try_lock() {
    assert_eq!(*guard, 10);
}

Trait Implementations

impl<T> Clone for Lock<T>[src]

impl<T: Debug> Debug for Lock<T>[src]

impl<T: Default> Default for Lock<T>[src]

impl<T> From<T> for Lock<T>[src]

impl<T: Send> Send for Lock<T>[src]

impl<T: Send> Sync for Lock<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Lock<T>

impl<T> Unpin for Lock<T>

impl<T> !UnwindSafe for Lock<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.