sync_cow 0.1.2

Thread-safe clone-on-write container for fast concurrent writing and reading.
Documentation
use std::any::Any;
use std::sync::Arc;
use sync_cow::SyncCow;

fn main() -> Result<(), Box<dyn Any + Send>> {
    let cow = Arc::new(SyncCow::new(5));

    // Arc is only needed to pass the ref to the threads
    let cow_write_arc = cow.clone();
    let cow_read_arc = cow.clone();

    let writer = std::thread::spawn(move || {
        let cow = &*cow_write_arc; // unpack immediately to avoid Arc deref
        let mut val = 0;
        cow.edit(|x| {
            val = *x;
            *x = 4;
        });
        println!("Cow was {} when writing", val);
    });

    let reader = std::thread::spawn(move || {
        let cow = &*cow_read_arc; // unpack immediately to avoid Arc deref
        println!("Cow was {} when reading", cow.read());
    });

    writer.join()?;
    reader.join()?;
    Ok(())
}