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]

[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).

[src]

Replaces the value inside this instance.

Further loads will yield the new value.

[src]

Exchanges the value inside this instance.

Trait Implementations

impl<T> From<Arc<T>> for ArcSwap<T>
[src]

[src]

Performs the conversion.

impl<T> Drop for ArcSwap<T>
[src]

[src]

Executes the destructor for this type. Read more

impl<T> Clone for ArcSwap<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Debug> Debug for ArcSwap<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T: Display> Display for ArcSwap<T>
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<T> Send for ArcSwap<T> where
    T: Send + Sync

impl<T> Sync for ArcSwap<T> where
    T: Send + Sync