Struct arc_swap::ArcSwap
[−]
[src]
pub struct ArcSwap<T> { /* fields omitted */ }
An atomic storage for Arc
.
This is a storage where an Arc
may live. It can be read and written atomically from several
threads, but doesn't act like a pointer itself.
One can be created from
an Arc
. To get an Arc
back, use the load
method.
Examples
let arc = Arc::new(42); let arc_swap = ArcSwap::from(arc); assert_eq!(42, *arc_swap.load()); // It can be read multiple times assert_eq!(42, *arc_swap.load()); // Put a new one in there let new_arc = Arc::new(0); assert_eq!(42, *arc_swap.swap(new_arc)); assert_eq!(0, *arc_swap.load());
Methods
impl<T> ArcSwap<T>
[src]
pub fn load(&self) -> Arc<T>
[src]
Loads the value.
This makes another copy (reference) and returns it, atomically (it is safe even when other thread stores into the same instance at the same time).
pub fn store(&self, arc: Arc<T>)
[src]
Replaces the value inside this instance.
Further loads will yield the new value.
pub fn swap(&self, arc: Arc<T>) -> Arc<T>
[src]
Exchanges the value inside this instance.
Trait Implementations
impl<T> From<Arc<T>> for ArcSwap<T>
[src]
impl<T> Drop for ArcSwap<T>
[src]
impl<T> Clone for ArcSwap<T>
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Debug> Debug for ArcSwap<T>
[src]
fn fmt(&self, formatter: &mut Formatter) -> FmtResult
[src]
Formats the value using the given formatter. Read more