Crate ring_buffer_macro

Crate ring_buffer_macro 

Source
Expand description

A procedural macro for creating compile-time ring buffers (circular buffers).

§Usage

use ring_buffer_macro::ring_buffer;

#[ring_buffer(5)]
struct IntBuffer {
    data: Vec<i32>,
}

let mut buf = IntBuffer::new();
buf.enqueue(1).unwrap();
buf.enqueue(2).unwrap();
assert_eq!(buf.dequeue(), Some(1));

§Generated Methods

  • new() - Create empty buffer
  • enqueue(item: T) -> Result<(), T> - Add item (returns Err(item) if full)
  • dequeue() -> Option<T> - Remove oldest item (requires T: Clone)
  • is_full(), is_empty(), len(), capacity(), clear()

§Requirements

  • Struct must have a field named data of type Vec<T>
  • Element type T must implement Clone

Attribute Macros§

ring_buffer
Transforms a struct with a Vec<T> field into a fixed-size FIFO ring buffer.