15 releases

0.2.14 Aug 13, 2025
0.2.13 Jun 11, 2025
0.2.12 May 15, 2025
0.2.11 Mar 20, 2025
0.1.0 Mar 13, 2022

#18 in Concurrency

Download history 230580/week @ 2025-08-26 221393/week @ 2025-09-02 220107/week @ 2025-09-09 219346/week @ 2025-09-16 220509/week @ 2025-09-23 220417/week @ 2025-09-30 234980/week @ 2025-10-07 238443/week @ 2025-10-14 238166/week @ 2025-10-21 267930/week @ 2025-10-28 256240/week @ 2025-11-04 262095/week @ 2025-11-11 256655/week @ 2025-11-18 157254/week @ 2025-11-25 233570/week @ 2025-12-02 406096/week @ 2025-12-09

1,107,045 downloads per month
Used in 629 crates (36 directly)

MIT license

83KB
1.5K SLoC

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

Dependencies

~0–18MB
~291K SLoC