| Crates.io | ibag |
| lib.rs | ibag |
| version | 0.3.5 |
| created_at | 2025-04-09 08:20:51.50402+00 |
| updated_at | 2025-05-08 07:28:01.253364+00 |
| description | A thread-safe, immutable bag for holding any value |
| homepage | |
| repository | https://github.com/open1s/ibag.git |
| max_upload_size | |
| id | 1626386 |
| size | 31,989 |
A Rust library providing a thread-safe, immutable bag container that allows safe concurrent access to shared data.
Add this to your Cargo.toml:
[dependencies]
ibag = "0.3"
use ibag::iBag;
// Create a new iBag
let bag = iBag::new(42);
// Read access
let value = bag.with_read(|val| *val);
assert_eq!(value, 42);
// Write access
bag.with(|val| *val = 100);
// Thread-safe operations
let bag = Arc::new(bag);
let handles: Vec<_> = (0..10).map(|_| {
let bag = bag.clone();
thread::spawn(move || {
bag.with(|val| *val += 1);
})
}).collect();
for handle in handles {
handle.join().unwrap();
}
See the API documentation for complete details.
MIT