| Crates.io | cowvert |
| lib.rs | cowvert |
| version | 0.1.1 |
| created_at | 2025-02-15 03:38:10.328724+00 |
| updated_at | 2025-02-16 16:16:25.426074+00 |
| description | a flexible data container supporting owned, reference-counted, and copy-on-write semantics. designed for use in interpreters |
| homepage | |
| repository | https://github.com/snowfoxsh/cowvert |
| max_upload_size | |
| id | 1556233 |
| size | 14,623 |
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.
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
}
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
}