pub struct RwLock<T: ?Sized>(/* private fields */);
Expand description
A wrapper around std::sync::RwLock
that panics on poison.
This RwLock
works similarly to the standard library’s RwLock
, except its
read
and write
methods do not return a Result
. Instead, if the lock is
poisoned, it will panic.
§Examples
use matrix_sdk_common::locks::RwLock;
let lock = RwLock::new(42);
{
let read_guard = lock.read();
assert_eq!(*read_guard, 42);
}
{
let mut write_guard = lock.write();
*write_guard = 100;
}
assert_eq!(*lock.read(), 100);
Implementations§
Source§impl<T: ?Sized> RwLock<T>
impl<T: ?Sized> RwLock<T>
Sourcepub fn write(&self) -> RwLockWriteGuard<'_, T>
pub fn write(&self) -> RwLockWriteGuard<'_, T>
Acquires a mutable write lock, panicking if the lock is poisoned.
This method blocks the current thread until the lock is acquired.
Sourcepub fn read(&self) -> RwLockReadGuard<'_, T>
pub fn read(&self) -> RwLockReadGuard<'_, T>
Acquires a shared read lock, panicking if the lock is poisoned.
This method blocks the current thread until the lock is acquired.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for RwLock<T>where
T: Deserialize<'de> + ?Sized,
impl<'de, T> Deserialize<'de> for RwLock<T>where
T: Deserialize<'de> + ?Sized,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> !Freeze for RwLock<T>
impl<T> RefUnwindSafe for RwLock<T>where
T: ?Sized,
impl<T> Send for RwLock<T>
impl<T> Sync for RwLock<T>
impl<T> Unpin for RwLock<T>
impl<T> UnwindSafe for RwLock<T>where
T: ?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
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Consume a handle, getting back the initial
Arc<>