pub struct RwLock<T: ?Sized> { /* private fields */ }
Expand description
A reader-writer lock synchronization primitive. This type allows multiple readers or one writer at a time.
This is different from a Mutex
because it allows for multiple readers at the same time.
Implementations§
Source§impl<T: ?Sized> RwLock<T>
impl<T: ?Sized> RwLock<T>
Sourcepub const fn read(&self) -> RwLockReadFuture<'_, T> ⓘ
pub const fn read(&self) -> RwLockReadFuture<'_, T> ⓘ
Obtains a read lock on the data. Multiple read locks can be held at the same time.
Sourcepub const fn write(&self) -> RwLockWriteFuture<'_, T> ⓘ
pub const fn write(&self) -> RwLockWriteFuture<'_, T> ⓘ
Obtains a write lock on the data. Only one write lock can be held at a time.
Sourcepub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>>
pub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>>
Attempt to gain a read lock on the data.
Sourcepub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>>
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>>
Attempt to gain a write lock on the data.
Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Get mutable access to the data stored in the read-write lock. This doesn’t require a lock to be acquired because the borrow checker guarantees exclusive access because self is a mutable reference.
Sourcepub fn into_inner(self) -> Twhere
T: Sized,
pub fn into_inner(self) -> Twhere
T: Sized,
Consumes the read-write lock and returns the inner data.
Trait Implementations§
impl<T: ?Sized + Send> Send for RwLock<T>
impl<T: ?Sized + Send + Sync> Sync for RwLock<T>
Auto Trait Implementations§
impl<T> !Freeze for RwLock<T>
impl<T> !RefUnwindSafe for RwLock<T>
impl<T> Unpin for RwLock<T>
impl<T> UnwindSafe for RwLock<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