pub struct ReplayBuffer { /* private fields */ }Expand description
An in-memory event replay buffer.
Events are appended sequentially. When the buffer exceeds max_capacity
the oldest event is evicted automatically. A cursor tracks the current
read position; seek / read operations advance it.
Implementations§
Source§impl ReplayBuffer
impl ReplayBuffer
Sourcepub fn new(max_capacity: usize) -> Self
pub fn new(max_capacity: usize) -> Self
Create a new ReplayBuffer with the given maximum capacity.
When max_capacity is 0 the buffer has no effective limit (usize::MAX).
Sourcepub fn append(&mut self, event: StreamEvent) -> Result<(), ReplayError>
pub fn append(&mut self, event: StreamEvent) -> Result<(), ReplayError>
Append a new event to the buffer.
If the buffer is at max_capacity the oldest event is evicted and the
cursor is adjusted so it never points past the start.
Sourcepub fn seek(&mut self, pos: SeekPosition) -> Result<usize, ReplayError>
pub fn seek(&mut self, pos: SeekPosition) -> Result<usize, ReplayError>
Move the read cursor to pos.
Returns the new cursor position on success.
Sourcepub fn read_next(&mut self) -> Option<&StreamEvent>
pub fn read_next(&mut self) -> Option<&StreamEvent>
Read the event at the current cursor position and advance the cursor.
Returns None when the cursor is past the last event.
Sourcepub fn read_batch(&mut self, count: usize) -> Vec<&StreamEvent>
pub fn read_batch(&mut self, count: usize) -> Vec<&StreamEvent>
Read up to count events starting at the current cursor, advancing
the cursor past each returned event.
Sourcepub fn events_remaining(&self) -> usize
pub fn events_remaining(&self) -> usize
Number of events remaining from the cursor to the end of the buffer.
Sourcepub fn stats(&self) -> ReplayStats
pub fn stats(&self) -> ReplayStats
Snapshot of current buffer statistics.
Auto Trait Implementations§
impl Freeze for ReplayBuffer
impl RefUnwindSafe for ReplayBuffer
impl Send for ReplayBuffer
impl Sync for ReplayBuffer
impl Unpin for ReplayBuffer
impl UnsafeUnpin for ReplayBuffer
impl UnwindSafe for ReplayBuffer
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.