clone-replace

Crates.ioclone-replace
lib.rsclone-replace
version0.1.1
sourcesrc
created_at2022-05-12 21:54:26.491535
updated_at2022-05-12 22:56:25.590872
descriptionShare mutable data by cloning and replacing a reference version
homepage
repositoryhttps://github.com/eds-collabora/clone-replace-rs
max_upload_size
id585498
size13,776
(eds-collabora)

documentation

README

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.

Commit count: 0

cargo fmt