pub struct RwLock<T> { /* private fields */ }
Expand description
Mock implementation of std::sync::RwLock
Implementations§
source§impl<T> RwLock<T>
impl<T> RwLock<T>
sourcepub fn read(&self) -> LockResult<RwLockReadGuard<'_, T>>
pub fn read(&self) -> LockResult<RwLockReadGuard<'_, T>>
Locks this rwlock with shared read access, blocking the current thread until it can be acquired.
The calling thread will be blocked until there are no more writers which hold the lock. There may be other readers currently inside the lock when this method returns. This method does not provide any guarantees with respect to the ordering of whether contentious readers or writers will acquire the lock first.
sourcepub fn try_read(&self) -> TryLockResult<RwLockReadGuard<'_, T>>
pub fn try_read(&self) -> TryLockResult<RwLockReadGuard<'_, T>>
Attempts to acquire this rwlock with shared read access.
If the access could not be granted at this time, then Err is returned. Otherwise, an RAII guard is returned which will release the shared access when it is dropped.
This function does not block.
sourcepub fn write(&self) -> LockResult<RwLockWriteGuard<'_, T>>
pub fn write(&self) -> LockResult<RwLockWriteGuard<'_, T>>
Locks this rwlock with exclusive write access, blocking the current thread until it can be acquired.
This function will not return while other writers or other readers currently have access to the lock.
sourcepub fn try_write(&self) -> TryLockResult<RwLockWriteGuard<'_, T>>
pub fn try_write(&self) -> TryLockResult<RwLockWriteGuard<'_, T>>
Attempts to lock this rwlock with exclusive write access.
If the lock could not be acquired at this time, then Err is returned. Otherwise, an RAII guard is returned which will release the lock when it is dropped.
This function does not block.
sourcepub fn get_mut(&mut self) -> LockResult<&mut T>
pub fn get_mut(&mut self) -> LockResult<&mut T>
Returns a mutable reference to the underlying data.
sourcepub fn into_inner(self) -> LockResult<T>
pub fn into_inner(self) -> LockResult<T>
Consumes this RwLock
, returning the underlying data.