Crates.io | clone-replace |
lib.rs | clone-replace |
version | 0.1.1 |
source | src |
created_at | 2022-05-12 21:54:26.491535 |
updated_at | 2022-05-12 22:56:25.590872 |
description | Share mutable data by cloning and replacing a reference version |
homepage | |
repository | https://github.com/eds-collabora/clone-replace-rs |
max_upload_size | |
id | 585498 |
size | 13,776 |
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);
This crate is made available under either an Apache-2.0 or an MIT license.