Skip to main content

AtomicCell

Struct AtomicCell 

Source
pub struct AtomicCell<T> { /* private fields */ }
Expand description

Thread-safe atomic cell wrapper

Implementations§

Source§

impl<T> AtomicCell<T>

Source

pub fn new(val: T) -> Self

Create a new atomic cell containing val

Source

pub fn get(&self) -> WatchGuardRef<'_, T>

Shared (read-only) access via sync

Source

pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

Executes a closure while holding a shared guard.

Source

pub fn get_mut(&self) -> WatchGuardMut<'_, T>

Exclusive mutable access via sync

Source

pub fn with_mut<R>(&self, f: impl FnOnce(&mut T) -> R) -> R

Executes a closure while holding an exclusive guard.

Source

pub fn as_ptr(&self) -> *mut T

Returns a raw pointer to the inner value

Source

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

pub fn update<F>(&self, f: F)
where F: FnMut(&mut T),

Atomic update with exclusive closure

Source

pub fn swap(&self, val: T) -> T

Swap the value, returning the old one

Source

pub fn store(&self, val: T)

Store a new value, dropping the old one

Source§

impl<T: Copy + Eq> AtomicCell<T>

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Drop for AtomicCell<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> RefUnwindSafe for AtomicCell<T>

Source§

impl<T: Send> Send for AtomicCell<T>

Source§

impl<T: Sync> Sync for AtomicCell<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.