pub struct LogRing<T> { /* private fields */ }Expand description
Circular buffer for log storage with FIFO eviction.
Memory-efficient storage that maintains a sliding window of the most recent items. Older items are evicted when capacity is reached.
Implementations§
Source§impl<T> LogRing<T>
impl<T> LogRing<T>
Sourcepub fn push(&mut self, item: T)
pub fn push(&mut self, item: T)
Add an item to the ring.
If the ring is at capacity, the oldest item is evicted first.
Sourcepub fn extend(&mut self, items: impl IntoIterator<Item = T>)
pub fn extend(&mut self, items: impl IntoIterator<Item = T>)
Add multiple items efficiently.
Sourcepub fn get(&self, absolute_idx: usize) -> Option<&T>
pub fn get(&self, absolute_idx: usize) -> Option<&T>
Get item by absolute index (across entire history).
Returns None if the index is out of range or the item has been evicted.
Sourcepub fn get_mut(&mut self, absolute_idx: usize) -> Option<&mut T>
pub fn get_mut(&mut self, absolute_idx: usize) -> Option<&mut T>
Get mutable reference by absolute index.
Sourcepub fn get_range(&self, range: Range<usize>) -> impl Iterator<Item = &T>
pub fn get_range(&self, range: Range<usize>) -> impl Iterator<Item = &T>
Get a range of items by absolute indices.
Returns references to items that are still in memory within the range. Items that have been evicted are skipped.
Sourcepub const fn total_count(&self) -> usize
pub const fn total_count(&self) -> usize
Total items ever added (including evicted).
Sourcepub fn first_index(&self) -> usize
pub fn first_index(&self) -> usize
First absolute index still in memory.
Sourcepub fn last_index(&self) -> Option<usize>
pub fn last_index(&self) -> Option<usize>
Last absolute index (most recent item).
Returns None if the ring is empty.
Sourcepub fn is_in_memory(&self, absolute_idx: usize) -> bool
pub fn is_in_memory(&self, absolute_idx: usize) -> bool
Check if an absolute index is still in memory.
Sourcepub fn evicted_count(&self) -> usize
pub fn evicted_count(&self) -> usize
Number of items that have been evicted.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all items.
Note: total_count is preserved for consistency with absolute indexing.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = &T>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T>
Iterate over items currently in memory (oldest to newest).
Sourcepub fn iter_indexed(&self) -> impl DoubleEndedIterator<Item = (usize, &T)>
pub fn iter_indexed(&self) -> impl DoubleEndedIterator<Item = (usize, &T)>
Iterate over items with their absolute indices.
Trait Implementations§
Source§impl<T> Extend<T> for LogRing<T>
impl<T> Extend<T> for LogRing<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)