pub struct CircularBuffer<T> { /* private fields */ }Expand description
A fixed-size circular buffer that automatically evicts the oldest items when the buffer is full. Useful for maintaining a rolling window of data.
Implementations§
Source§impl<T> CircularBuffer<T>
impl<T> CircularBuffer<T>
Sourcepub fn add(&mut self, item: T)
pub fn add(&mut self, item: T)
Add an item to the buffer. If the buffer is full, the oldest item will be evicted.
Sourcepub fn add_all(&mut self, items: impl IntoIterator<Item = T>)
pub fn add_all(&mut self, items: impl IntoIterator<Item = T>)
Add multiple items to the buffer at once.
Sourcepub fn get_recent(&self, count: usize) -> Vec<&T>
pub fn get_recent(&self, count: usize) -> Vec<&T>
Get the most recent N items from the buffer. Returns fewer items if the buffer contains less than N items.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CircularBuffer<T>
impl<T> RefUnwindSafe for CircularBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for CircularBuffer<T>where
T: Send,
impl<T> Sync for CircularBuffer<T>where
T: Sync,
impl<T> Unpin for CircularBuffer<T>where
T: Unpin,
impl<T> UnsafeUnpin for CircularBuffer<T>
impl<T> UnwindSafe for CircularBuffer<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