AsyncRWLock

Struct AsyncRWLock 

Source
pub struct AsyncRWLock<T> { /* private fields */ }
Expand description

An async mutex lock that can be used in async functions to prevent blocking current execution while waiting for the lock to become available. So for this to work the lock method does not return a WriteGuard immediately but a Future that will resolve into a AsyncWriteLockGuard when awaited. In the same way the read method will return a Future resolving to an AsyncReadLockGuard when awaited.

Implementations§

Source§

impl<T> AsyncRWLock<T>

Source

pub fn new(value: T) -> Self

Create the AsyncRWLock

Source

pub async fn write(&self) -> AsyncWriteLockGuard<'_, T>

Locking the data for write access secured by the AsyncRWLock will yield a Future that must be awaited to actually acquire the lock.

Source

pub fn write_blocking(&self) -> WriteLockGuard<'_, T>

Source

pub async fn read(&self) -> AsyncReadLockGuard<'_, T>

Locking the data for read access secured by the AsyncRWLock will yield a Future that must be awaited to actually acquire the lock.

Source

pub fn into_inner(self) -> Result<T, Self>

Provide the inner data wrapped by this AsyncRWLock. This will only provide the contained data if there is only one active reference to it. If the data is still shared more than once, eg. because there are active Futures awaiting a lock this will return the actual AsyncRWLock in the Err variant.

Auto Trait Implementations§

§

impl<T> Freeze for AsyncRWLock<T>

§

impl<T> !RefUnwindSafe for AsyncRWLock<T>

§

impl<T> Send for AsyncRWLock<T>
where T: Send,

§

impl<T> Sync for AsyncRWLock<T>
where T: Send,

§

impl<T> Unpin for AsyncRWLock<T>

§

impl<T> !UnwindSafe for AsyncRWLock<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.