Struct RwLock
pub struct RwLock<T>(/* private fields */)
where
T: ?Sized;
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§
§impl<T> RwLock<T>where
T: ?Sized,
impl<T> RwLock<T>where
T: ?Sized,
pub 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.
pub 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§
§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,
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<RwLock<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<RwLock<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl<T> Serialize for RwLock<T>
impl<T> Serialize for RwLock<T>
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. 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<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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