Hey everyone! I recently published qring, a lightweight, zero-allocation, lock-free ring buffer with #![no_std] rust.
I'm sharing it here to get feedback about my code and show the areas to improve the efficiency of the implementation.
Key Architectural Details
-
SPSC Queue (for now): Implemented Single-Producer Single-Consumer for now. Support for MPSC, SPMC, and MPMC topologies are currently in development.
-
Slice Batching (
pop_slice,push_exact): Allows moving chunks of data at once instead of doing single-element updations, reducing atomic synchronization overhead during bulk transfers. -
no_stdReady: Runs on bare-metal and embedded systems without requiring a dynamic memory allocator. Focuses primarily to get as fast as it could. -
Cache-Aligned (
#[repr(align(64))]): Producer and consumer state sit on separate cache lines to prevent false sharing across CPU cores. -
Strict Atomics: Built around explicit
Acquire/Releasememory orderings for lock-free safety without unnecessary CPU fences.
Quick Example
Rust
use qring::spsc::SpscQueue;
fn main() {
// Split into producer/consumer handles (capacity: 1024)
let (mut producer, mut consumer) = SpscQueue::<u8, 1024>::split();
// Push batch data efficiently
let data = [1, 2, 3, 4, 5];
let _ = producer.push_exact(&data);
// Pop straight into a slice
let mut read_buf = [0u8; 5];
let popped = consumer.pop_slice(&mut read_buf); // returns the count of popped elements
assert_eq!(popped, 5);
assert_eq!(read_buf, [1, 2, 3, 4, 5]);
}
Looking for Feedback
Since it is my first time in no_std rust, i would like some feedback from the community about the implementation, and share how useful it would be in real world applications.
Links
If you find qring interesting or useful, feel free to star the repository on GitHub—it really helps with visibility! Looking forward to hear your thoughts and suggestions.