pub struct RingBuffer<T: Clone> { /* private fields */ }Expand description
A lock-free ring buffer for metric storage
This implementation uses atomic operations to avoid locks in the hot path, ensuring minimal impact on trading system performance.
Implementations§
Source§impl<T: Clone> RingBuffer<T>
impl<T: Clone> RingBuffer<T>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new ring buffer with the specified capacity
§Arguments
capacity- Buffer capacity, must be a power of 2 (2, 4, 8, 16, 32, 64, 128, …)
§Returns
A new RingBuffer with effective capacity of capacity - 1 items.
§Panics
Panics if capacity is not a power of 2 or is zero.
§Example
let buffer = RingBuffer::new(1024); // Can hold 1023 itemsSourcepub fn pop(&self) -> Option<T>
pub fn pop(&self) -> Option<T>
Pop an item from the ring buffer
§Returns
Some(item) if an item was available, None if the buffer was empty
Sourcepub fn overflow_count(&self) -> usize
pub fn overflow_count(&self) -> usize
Returns the total number of overflow events
Sourcepub fn reset_overflow_count(&self)
pub fn reset_overflow_count(&self)
Resets the overflow counter to zero
Trait Implementations§
impl<T: Clone + Send> Send for RingBuffer<T>
impl<T: Clone + Send> Sync for RingBuffer<T>
Auto Trait Implementations§
impl<T> !Freeze for RingBuffer<T>
impl<T> !RefUnwindSafe for RingBuffer<T>
impl<T> Unpin for RingBuffer<T>where
T: Unpin,
impl<T> UnwindSafe for RingBuffer<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more