pub struct SharedRw<T>(/* private fields */);Expand description
Thread-safe shared value using RwLock for concurrent reads and exclusive writes.
Implementations§
Sourcepub fn read<F, R>(&self, f: F) -> Result<R, PoisonError<RwLockReadGuard<'_, T>>>
pub fn read<F, R>(&self, f: F) -> Result<R, PoisonError<RwLockReadGuard<'_, T>>>
Execute a closure with read-only access.
Caution: f runs while the read lock is held. Avoid re-entering this
SharedRw from inside the closure, especially for writes.
Sourcepub fn write<F, R>(
&self,
f: F,
) -> Result<R, PoisonError<RwLockWriteGuard<'_, T>>>
pub fn write<F, R>( &self, f: F, ) -> Result<R, PoisonError<RwLockWriteGuard<'_, T>>>
Execute a closure with mutable access.
Caution: f runs while the write lock is held. Avoid re-entering this
SharedRw from inside the closure.
Sourcepub fn get(&self) -> Result<T, PoisonError<RwLockReadGuard<'_, T>>>where
T: Clone,
pub fn get(&self) -> Result<T, PoisonError<RwLockReadGuard<'_, T>>>where
T: Clone,
Get a cloned snapshot of the value.
Sourcepub fn set(&self, value: T) -> Result<(), PoisonError<RwLockWriteGuard<'_, T>>>
pub fn set(&self, value: T) -> Result<(), PoisonError<RwLockWriteGuard<'_, T>>>
Replace the inner value.
Trait Implementations§
Auto Trait Implementations§
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