FAQ

Why does dequeue require Clone in standard mode?

Standard mode stores items in a Vec<T> and copies them out on dequeue. This is a deliberate simplicity trade-off for single-threaded use.

Concurrent modes (SPSC, MPSC) use MaybeUninit<T> to move items instead of cloning, so they only require T: Send.


Can I use a const for capacity?

No. Procedural macros operate on token streams before const evaluation happens. The capacity must be a literal integer.

// This works:
#[ring_buffer(256)]
struct Buffer(i32);
// This does NOT work:
const SIZE: usize = 256;
#[ring_buffer(SIZE)] // Error: expected literal
struct Buffer(i32);

How does this compare to VecDeque?

Featurering-buffer-macroVecDeque
Fixed capacitycompile-timegrows dynamically
Heap allocationonce, fixedamortized, may reallocate
Thread-safe modesSPSC, MPSCnone
API surface~12 methods40+ methods
Code generationcompile-timeruntime generics
Iterator supportiter, drainfull iterator suite

Use VecDeque when you need a growable deque with a rich API. Use ring-buffer-macro when you need fixed-size, bounded buffers — especially in concurrent or embedded contexts.


What about MPMC (multi-producer, multi-consumer)?

MPMC was included in an early version but removed in v0.2.0 due to reliability issues. Correct MPMC requires significantly more complex synchronization. For MPMC needs, use established crates like crossbeam-channel or flume.


What Rust edition is required?

Rust 2021 edition (edition = "2021" in Cargo.toml). The crate uses syn 2.0, quote 1.0, and proc-macro2 1.0 as build dependencies.


The macro isn't expanding correctly

Common issues:

  • Must be a tuple structstruct Buffer(i32), not struct Buffer { data: i32 }
  • Exactly one field requiredZero or multiple fields will produce a compile error
  • Capacity must be a positive integer literalNo constants, expressions, or type parameters
  • power_of_two requires 2^n capacity256, 512, 1024 are valid; 100, 300 are not

Use cargo expand to see the generated code if you suspect a macro expansion issue:

cargo install cargo-expand
cargo expand

Can I have multiple fields?

No. The macro requires exactly one field — the element type. The tuple struct is transformed into a named struct with internal fields (data, head, tail, size, capacity). Your single field becomes the type parameter for the internal Vec<T>.


How do I contribute?

The project is open source under the MIT license. Contributions are welcome.

  • 1.Fork the repository on GitHub
  • 2.Create a feature branch
  • 3.Run the test suite with cargo test
  • 4.Submit a pull request

Repository: github.com/0xsouravm/ring-buffer-macro