pub struct AtomicCell<T> { /* private fields */ }Expand description
Thread-safe atomic cell wrapper
Implementations§
Source§impl<T> AtomicCell<T>
impl<T> AtomicCell<T>
Sourcepub fn get(&self) -> WatchGuardRef<'_, T>
pub fn get(&self) -> WatchGuardRef<'_, T>
Shared (read-only) access via sync
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Executes a closure while holding a shared guard.
Sourcepub fn get_mut(&self) -> WatchGuardMut<'_, T>
pub fn get_mut(&self) -> WatchGuardMut<'_, T>
Exclusive mutable access via sync
Sourcepub fn with_mut<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
pub fn with_mut<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
Executes a closure while holding an exclusive guard.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the AtomicCell and returns the inner value.
§Panics
Panics if there are other clones of this AtomicCell still alive.
Source§impl<T: Copy + Eq> AtomicCell<T>
impl<T: Copy + Eq> AtomicCell<T>
Sourcepub fn compare_exchange(
&self,
current: T,
new: T,
) -> Result<T, WatchGuardMut<'_, T>>
pub fn compare_exchange( &self, current: T, new: T, ) -> Result<T, WatchGuardMut<'_, T>>
Compare-and-swap: if current == stored, write new and return Ok(old). Otherwise return Err with the guard still held.
Trait Implementations§
Source§impl<T> Clone for AtomicCell<T>
impl<T> Clone for AtomicCell<T>
Source§impl<T> Drop for AtomicCell<T>
impl<T> Drop for AtomicCell<T>
impl<T> RefUnwindSafe for AtomicCell<T>
impl<T: Send> Send for AtomicCell<T>
impl<T: Sync> Sync for AtomicCell<T>
impl<T> UnwindSafe for AtomicCell<T>
Auto Trait Implementations§
impl<T> Freeze for AtomicCell<T>
impl<T> Unpin for AtomicCell<T>
impl<T> UnsafeUnpin for AtomicCell<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