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) -> RwLock<T>
pub const fn new(value: T) -> RwLock<T>
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> UnsafeUnpin for RwLock<T>where
T: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more