cowvert

Crates.iocowvert
lib.rscowvert
version0.1.1
created_at2025-02-15 03:38:10.328724+00
updated_at2025-02-16 16:16:25.426074+00
descriptiona flexible data container supporting owned, reference-counted, and copy-on-write semantics. designed for use in interpreters
homepage
repositoryhttps://github.com/snowfoxsh/cowvert
max_upload_size
id1556233
size14,623
Patrick Unick (snowfoxsh)

documentation

README

A simple library for creating references and copy on write values.

It is designed to be used in interpreters for handling the env.

See the tests to learn more.


Example Usage

Converting Between Value and Reference

use cowvert::Data;

fn main() {
    let mut data = Data::value(100);
    assert!(data.is_val());

    let mut ref_data = data.by_ref();
    assert!(ref_data.is_ref());

    *ref_data.borrow_mut() += 50;
    
    assert_eq!(*data.borrow(), 150); // mutates the original
}

Copy-on-Write (COW)

use cowvert::Data;

fn main() {
    let mut data = Data::value("hello".to_string());

    let mut cow_data = data.by_cow();
    *cow_data.borrow_mut() = "goodbye".to_string();

    assert_eq!(*data.borrow(), "hello"); // original remains unchanged
    assert_eq!(*cow_data.borrow(), "goodbye"); // copy is modified
}
Commit count: 15

cargo fmt