#[repr(align(64))]pub struct CircularBuffer<T, const N: usize> { /* private fields */ }Expand description
Cache-friendly fixed-size circular buffer optimized for HFT applications Uses a contiguous memory layout and avoids heap allocations
Implementations§
Source§impl<T, const N: usize> CircularBuffer<T, N>
impl<T, const N: usize> CircularBuffer<T, N>
Sourcepub fn push(&mut self, item: T) -> bool
pub fn push(&mut self, item: T) -> bool
Add an element to the buffer Returns true if successful, false if buffer is full
Sourcepub const fn pop(&mut self) -> Option<T>
pub const fn pop(&mut self) -> Option<T>
Remove and return the oldest element from the buffer Returns None if the buffer is empty
Sourcepub const fn peek(&self) -> Option<&T>
pub const fn peek(&self) -> Option<&T>
Peek at the oldest element without removing it Returns None if the buffer is empty
Sourcepub const fn get(&self, index: usize) -> Option<&T>
pub const fn get(&self, index: usize) -> Option<&T>
Get a reference to an element at a specific index relative to the read position Returns None if the index is out of bounds
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Get a mutable reference to an element at a specific index relative to the read position Returns None if the index is out of bounds
Sourcepub fn for_each_mut<F>(&mut self, f: F)
pub fn for_each_mut<F>(&mut self, f: F)
Execute a function on each element in the buffer, allowing mutation
Sourcepub fn to_vec(&self) -> Vec<T>where
T: Clone,
pub fn to_vec(&self) -> Vec<T>where
T: Clone,
Convert the buffer to a Vec, consuming the buffer
Sourcepub fn push_overwrite(&mut self, item: T) -> bool
pub fn push_overwrite(&mut self, item: T) -> bool
Overwrite the oldest element if the buffer is full Always returns true (as it will always add the item)