#sync #non-blocking #synchronization

clone-replace

Share mutable data by cloning and replacing a reference version

2 releases

0.1.1 May 12, 2022
0.1.0 May 12, 2022

#1199 in Concurrency


Used in 4 crates (3 directly)

Apache-2.0 OR MIT

14KB
170 lines

clone-replace - share data by copying a reference

CloneReplace provides an evolving reference version of some data. When the data is accessed, you are returned an Arc handle to a snapshot of the reference as it existed at that moment. When you wish to mutate your data, a full copy is made of it, which you can update independently, without blocking any readers. Upon completing your modifications, the copy will be written back to become the new reference version.

Example:

use clone_replace::CloneReplace;

let data = CloneReplace::new(1);

let v1 = data.access();
assert_eq!(*v1, 1);
{
   let mut m = data.mutate();
   *m = 2;
   let v2 = data.access();
   assert_eq!(*v1, 1);
   assert_eq!(*v2, 1);
}
let v3 = data.access();
assert_eq!(*v3, 2);
assert_eq!(*v1, 1);

License

This crate is made available under either an Apache-2.0 or an MIT license.

Dependencies

~185KB