ibag

Crates.ioibag
lib.rsibag
version0.3.5
created_at2025-04-09 08:20:51.50402+00
updated_at2025-05-08 07:28:01.253364+00
descriptionA thread-safe, immutable bag for holding any value
homepage
repositoryhttps://github.com/open1s/ibag.git
max_upload_size
id1626386
size31,989
Brian G (gaobrian)

documentation

README

iBag - Thread-safe Immutable Bag

A Rust library providing a thread-safe, immutable bag container that allows safe concurrent access to shared data.

Features

  • Thread-safe immutable container
  • Read and write operations with automatic locking
  • Closure-based access patterns
  • Automatic Clone, Send and Sync implementations

Installation

Add this to your Cargo.toml:

[dependencies]
ibag = "0.3"

Usage

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();
}

API Documentation

See the API documentation for complete details.

License

MIT

Commit count: 0

cargo fmt