pub struct RingBuffer<T> { /* private fields */ }Expand description
Bounded FIFO ring buffer for inspector captures. Adding to a full buffer evicts the oldest entry. Reads return a snapshot in chronological order (oldest first).
Implementations§
Source§impl<T: Clone> RingBuffer<T>
impl<T: Clone> RingBuffer<T>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Build a new buffer. Capacity must be > 0; capacity 0 is clamped
to 1 to keep push infallible.
Sourcepub fn push(&mut self, item: T) -> Option<T>
pub fn push(&mut self, item: T) -> Option<T>
Push item; if the buffer was full, return the evicted oldest
entry. Callers that maintain side-tables keyed off the entry
(the inspector bridge’s details map keyed by seq) use the
returned item to clean up in lockstep so the side-table never
grows past the ring’s capacity.
pub fn snapshot(&self) -> Vec<T>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
Trait Implementations§
Source§impl<T: Clone> Clone for RingBuffer<T>
impl<T: Clone> Clone for RingBuffer<T>
Source§fn clone(&self) -> RingBuffer<T>
fn clone(&self) -> RingBuffer<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for RingBuffer<T>
impl<T> RefUnwindSafe for RingBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for RingBuffer<T>where
T: Send,
impl<T> Sync for RingBuffer<T>where
T: Sync,
impl<T> Unpin for RingBuffer<T>where
T: Unpin,
impl<T> UnsafeUnpin for RingBuffer<T>
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