cowvert 0.1.1

a flexible data container supporting owned, reference-counted, and copy-on-write semantics. designed for use in interpreters
Documentation
  • Coverage
  • 0%
    0 out of 22 items documented0 out of 14 items with examples
  • Size
  • Source code size: 14.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.97 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • snowfoxsh/cowvert
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • snowfoxsh

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
}