Skip to main content

LogRing

Struct LogRing 

Source
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>

Source

pub fn new(capacity: usize) -> Self

Create a new LogRing with the specified capacity.

§Panics

Panics if capacity is 0.

Source

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.

Source

pub fn extend(&mut self, items: impl IntoIterator<Item = T>)

Add multiple items efficiently.

Source

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.

Source

pub fn get_mut(&mut self, absolute_idx: usize) -> Option<&mut T>

Get mutable reference by absolute index.

Source

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.

Source

pub const fn total_count(&self) -> usize

Total items ever added (including evicted).

Source

pub fn len(&self) -> usize

Number of items currently in memory.

Source

pub fn is_empty(&self) -> bool

Check if the ring is empty.

Source

pub const fn capacity(&self) -> usize

Maximum capacity of the ring.

Source

pub fn first_index(&self) -> usize

First absolute index still in memory.

Source

pub fn last_index(&self) -> Option<usize>

Last absolute index (most recent item).

Returns None if the ring is empty.

Source

pub fn is_in_memory(&self, absolute_idx: usize) -> bool

Check if an absolute index is still in memory.

Source

pub fn evicted_count(&self) -> usize

Number of items that have been evicted.

Source

pub fn clear(&mut self)

Clear all items.

Note: total_count is preserved for consistency with absolute indexing.

Source

pub fn reset(&mut self)

Clear all items and reset counters.

Source

pub fn back(&self) -> Option<&T>

Get the most recent item.

Source

pub fn front(&self) -> Option<&T>

Get the oldest item still in memory.

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T>

Iterate over items currently in memory (oldest to newest).

Source

pub fn iter_indexed(&self) -> impl DoubleEndedIterator<Item = (usize, &T)>

Iterate over items with their absolute indices.

Source

pub fn drain(&mut self) -> impl Iterator<Item = T> + '_

Drain all items from the ring.

Trait Implementations§

Source§

impl<T: Clone> Clone for LogRing<T>

Source§

fn clone(&self) -> LogRing<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for LogRing<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for LogRing<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Extend<T> for LogRing<T>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> FromIterator<T> for LogRing<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<T> Freeze for LogRing<T>

§

impl<T> RefUnwindSafe for LogRing<T>
where T: RefUnwindSafe,

§

impl<T> Send for LogRing<T>
where T: Send,

§

impl<T> Sync for LogRing<T>
where T: Sync,

§

impl<T> Unpin for LogRing<T>
where T: Unpin,

§

impl<T> UnwindSafe for LogRing<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more