arc-atomic-ref 1.0.0

arc-atomic-ref is a small library that wraps arc-swap in Arc<T> so the atomic reference can be shared widely between many tasks/threads
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented1 out of 3 items with examples
  • Size
  • Source code size: 7.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.46 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • bluecatengineering/arc-atomic-ref
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • leshow

arc-atomic-ref

an AtomicRef is a smart pointer type that can be shared with many different threads of execution, while at the same time can be swapped out atomically with new data. In this way, it's similar to a lock-free RwLock or Mutex when you can replace the contained data rather than modify it.

use arc_atomic_ref::AtomicRef;
use std::sync::Arc;
let ptr = AtomicRef::new(1);
// share ptr with many threads with `clone`
// change its contained value, requires a new `Arc`
ptr.swap(Arc::new(2));
// all threads should see the change, use `.load()` to get the value
assert_eq!(**ptr.load(), 2);