AtomicArc

Struct AtomicArc 

Source
pub struct AtomicArc<T: 'static> { /* private fields */ }
Expand description

An Arc with an atomically updatable pointer.

Usage notes:

  • An AtomicArc can intrinsically store None (a hypothetical Option<AtomicArc<T>> would no longer be atomic).
  • An AtomicArc contributes to the strong count of the pointed-to allocation, if any. However, it does not implement Deref, so methods like load must be used to obtain a Guard through which the data can be accessed.
  • T must be Sized. This may be relaxed in the future.
  • When an AtomicArc is updated or dropped, the strong count of the previously pointed-to object may not be immediately decremented. Thus:
    • T must be 'static to support delayed deallocations.
    • The value returned by ref_count may be an overestimate.

§Examples

use aarc::{Arc, AtomicArc, Guard};

// ref count: 1
let x = Arc::new(53);
assert_eq!(Arc::ref_count(&x), 1);

// ref count: 2
let atomic = AtomicArc::new(0);
atomic.store(Some(&x));
assert_eq!(Arc::ref_count(&x), 2);

// guard doesn't affect the ref count
let guard = atomic.load().unwrap();
assert_eq!(Arc::ref_count(&x), 2);

// both the `Arc` and the `Guard` point to the same block
assert_eq!(*guard, 53);
assert_eq!(*guard, *x);

Implementations§

Source§

impl<T: 'static> AtomicArc<T>

Source

pub fn new<D: Into<Option<T>>>(data: D) -> Self

Similar to Arc::new, but None is a valid input, in which case the AtomicArc will store a null pointer.

To create an AtomicArc from an existing Arc, use from.

Source

pub fn load(&self) -> Option<Guard<'static, T>>

Loads a Guard, which allows the pointed-to value to be accessed. None indicates that the inner atomic pointer is null.

Source

pub fn swap<N: Into<NonNull<T>>>(&self, new: Option<N>) -> Option<Arc<T>>

Stores new’s pointer (or None) into self and returns the previously-stored Arc.

Source

pub fn store<N: Into<NonNull<T>>>(&self, new: Option<N>)

Stores new’s pointer (or None) into self. Equivalent to swap, but discards the result.

Trait Implementations§

Source§

impl<T: 'static> Clone for AtomicArc<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: 'static> CompareExchange<T, &Arc<T>> for AtomicArc<T>

Source§

fn compare_exchange<C: Into<NonNull<T>>>( &self, current: Option<C>, new: Option<&Arc<T>>, ) -> Result<(), Option<Guard<'static, T>>>

Source§

impl<T: 'static> CompareExchange<T, &Guard<'static, T>> for AtomicArc<T>

Source§

fn compare_exchange<C: Into<NonNull<T>>>( &self, current: Option<C>, new: Option<&Guard<'static, T>>, ) -> Result<(), Option<Guard<'static, T>>>

Source§

impl<T: Default + 'static> Default for AtomicArc<T>

Source§

fn default() -> AtomicArc<T>

Returns the “default value” for a type. Read more
Source§

impl<T: 'static> Drop for AtomicArc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: 'static, P: Into<NonNull<T>>> From<P> for AtomicArc<T>

Source§

fn from(value: P) -> Self

Converts to this type from the input type.
Source§

impl<T: 'static + Send + Sync> Send for AtomicArc<T>

Source§

impl<T: 'static + Send + Sync> Sync for AtomicArc<T>

Auto Trait Implementations§

§

impl<T> !Freeze for AtomicArc<T>

§

impl<T> RefUnwindSafe for AtomicArc<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for AtomicArc<T>
where T: Unpin,

§

impl<T> UnwindSafe for AtomicArc<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.