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 bufferenqueue(item: T) -> Result<(), T>- Add item (returnsErr(item)if full)dequeue() -> Option<T>- Remove oldest item (requiresT: Clone)is_full(),is_empty(),len(),capacity(),clear()
§Requirements
- Struct must have a field named
dataof typeVec<T> - Element type
Tmust implementClone
Attribute Macros§
- ring_
buffer - Transforms a struct with a
Vec<T>field into a fixed-size FIFO ring buffer.