pub struct RwLock<T> { /* private fields */ }
Expand description
A reader-writer lock which is exclusively locked for writing or shared for reading.
This reader-writer lock will block threads waiting for the lock to become available.
The lock can also be statically initialized or created via a RwLock::new
RwLock wrapper to make spin::RwLock
API compatible with std::sync::RwLock
to swap
Implementations§
Source§impl<T> RwLock<T>
impl<T> RwLock<T>
Sourcepub const fn new(value: T) -> Self
pub const fn new(value: T) -> Self
Creates a new reader-writer lock in an unlocked state ready for use.
Sourcepub fn read(&self) -> Result<RwLockReadGuard<'_, T>, String>
pub fn read(&self) -> Result<RwLockReadGuard<'_, T>, String>
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
Sourcepub fn write(&self) -> Result<RwLockWriteGuard<'_, T>, String>
pub fn write(&self) -> Result<RwLockWriteGuard<'_, T>, String>
Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for RwLock<T>
impl<T> RefUnwindSafe for RwLock<T>
impl<T> Send for RwLock<T>where
T: Send,
impl<T> Sync for RwLock<T>
impl<T> Unpin for RwLock<T>where
T: Unpin,
impl<T> UnwindSafe for RwLock<T>
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