#atomic

atomic_immut

Atomic immutable value

5 releases

Uses old Rust 2015

0.1.4 Feb 5, 2018
0.1.3 Jan 6, 2018
0.1.2 Sep 27, 2017
0.1.1 May 5, 2017
0.1.0 May 5, 2017

#43 in #atomic

Download history 84/week @ 2021-06-29 68/week @ 2021-07-06 103/week @ 2021-07-13 134/week @ 2021-07-20 70/week @ 2021-07-27 87/week @ 2021-08-03 92/week @ 2021-08-10 137/week @ 2021-08-17 126/week @ 2021-08-24 47/week @ 2021-08-31 69/week @ 2021-09-07 85/week @ 2021-09-14 92/week @ 2021-09-21 85/week @ 2021-09-28 112/week @ 2021-10-05 95/week @ 2021-10-12

534 downloads per month
Used in 25 crates (10 directly)

MIT license

10KB
164 lines

atomic_immut

Crates.io: atomic_immut Documentation Build Status Code Coverage License: MIT

Atomic immutable value for Rust.

Documentation


lib.rs:

Atomic immutable value.

Examples

use std::sync::Arc;
use std::thread;
use atomic_immut::AtomicImmut;

let v = Arc::new(AtomicImmut::new(vec![0]));
{
    let v = v.clone();
    thread::spawn(move || {
                      let mut new = (&*v.load()).clone(); // Loads the immutable reference
                      new.push(1);
                      v.store(new); // Replaces the existing value
                  });
}
while v.load().len() == 1 {}
assert_eq!(&*v.load(), &vec![0, 1]);

No runtime deps