10 stable releases

2.5.1 Feb 21, 2025
2.4.1 Jul 24, 2022
2.2.0 Dec 19, 2020
2.0.0 Jan 1, 2017
1.0.2 Mar 20, 2016

#202 in Concurrency

Download history 11/week @ 2024-12-04 27/week @ 2024-12-11 12/week @ 2024-12-25 15/week @ 2025-01-29 11/week @ 2025-02-12 354/week @ 2025-02-19 193/week @ 2025-02-26 377/week @ 2025-03-05 261/week @ 2025-03-12 216/week @ 2025-03-19

1,088 downloads per month

MIT license

50KB
1K SLoC

Magnetic

Crates.io Build Status License

Magnetic contains a set of high-performance queues useful for developing low-latency applications. All queues are FIFO unless otherwise specified.

More information can be found in the Docs


lib.rs:

Magnetic contains a set of high-performance queues useful for developing low-latency applications. All queues are FIFO unless otherwise specified.

Examples

use std::thread::spawn;
use magnetic::spsc::spsc_queue;
use magnetic::buffer::dynamic::DynamicBuffer;
use magnetic::{Producer, Consumer};

let (p, c) = spsc_queue(DynamicBuffer::new(32).unwrap());

// Push and pop within a single thread
p.push(1).unwrap();
assert_eq!(c.pop(), Ok(1));

// Push and pop from multiple threads. Since this example is using the
// SPSC queue, only one producer and one consumer are allowed.
let t1 = spawn(move || {
    for i in 0..10 {
        println!("Producing {}", i);
        p.push(i).unwrap();
    }
    p
});

let t2 = spawn(move || {
    loop {
        let i = c.pop().unwrap();
        println!("Consumed {}", i);
        if i == 9 { break; }
    }
});

t1.join().unwrap();
t2.join().unwrap();

Dependencies

~110KB