pub struct SharedRingBuffer<T: Clone> { /* private fields */ }Expand description
A thread-safe wrapper around RingBuffer for shared access
Implementations§
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new shared ring buffer with the specified capacity
This is the primary interface for creating ring buffers in the HFT system.
The buffer is wrapped in an Arc for efficient sharing between threads.
§Arguments
capacity- Buffer capacity, must be a power of 2 (2, 4, 8, 16, 32, 64, 128, …)
§Returns
A SharedRingBuffer with effective capacity of capacity - 1 items.
§Panics
Panics if capacity is not a power of 2 or is zero.
§Example
let buffer = SharedRingBuffer::new(1024); // For high-frequency dataSourcepub fn overflow_count(&self) -> usize
pub fn overflow_count(&self) -> usize
Returns the number of times the ring buffer has overflowed
An overflow occurs when push() is called on a full buffer, resulting in data loss.
This counter is critical for monitoring buffer saturation and capacity planning.
§Returns
The total number of overflow events since buffer creation or last reset.
§Example
let buffer = SharedRingBuffer::new(64);
// Monitor overflow rate
let initial = buffer.overflow_count();
// ... time passes ...
let overflows = buffer.overflow_count() - initial;
if overflows > 0 {
eprintln!("Warning: {} overflows detected", overflows);
}Trait Implementations§
Auto Trait Implementations§
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