boxcar

Crates.ioboxcar
lib.rsboxcar
version
sourcesrc
created_at2022-03-13 20:24:50.161442+00
updated_at2025-02-17 05:58:34.256098+00
descriptionA concurrent, append-only vector
homepage
repositoryhttps://github.com/ibraheemdev/boxcar
max_upload_size
id549414
Cargo.toml error:TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Ibraheem Ahmed (ibraheemdev)

documentation

README

boxcar

crates.io github docs.rs

A concurrent, append-only vector.

The vector provided by this crate supports lock-free get and push operations. The vector grows internally but never reallocates, so element addresses are stable for the lifetime of the vector. Additionally, both get and push run in constant-time.

Examples

Appending an element to a vector and retrieving it:

let vec = boxcar::Vec::new();
let i = vec.push(42);
assert_eq!(vec[i], 42);

The vector can be modified by multiple threads concurrently:

let vec = boxcar::Vec::new();

// Spawn a few threads that append to the vector.
std::thread::scope(|s| for i in 0..6 {
    let vec = &vec;

    s.spawn(move || {
        // Push through the shared reference.
        vec.push(i);
    });
});

for i in 0..6 {
    assert!(vec.iter().any(|(_, &x)| x == i));
}

Elements can be mutated through fine-grained locking:

let vec = boxcar::Vec::new();

std::thread::scope(|s| {
    // Insert an element.
    vec.push(std::sync::Mutex::new(0));

    s.spawn(|| {
        // Mutate through the lock.
        *vec[0].lock().unwrap() += 1;
    });
});

let x = vec[0].lock().unwrap();
assert_eq!(*x, 1);
Commit count: 79

cargo fmt