pub struct EventRingBuffer { /* private fields */ }Expand description
Fixed-size ring buffer for storing recent events.
When the buffer is full, new events overwrite the oldest entries. The default capacity is 1024 events.
§Examples
use grafos_observe::{EventRingBuffer, FabricEvent, ResourceType};
let mut ring = EventRingBuffer::new(4);
ring.push(FabricEvent::LeaseAcquired {
resource_type: ResourceType::Mem,
lease_id: 1,
node: "node-a".into(),
bytes: 4096,
trace_id: None,
});
assert_eq!(ring.len(), 1);
// Iterate over stored events (oldest first)
for event in ring.iter() {
println!("{event}");
}
// Drain removes and returns all events
let events = ring.drain();
assert!(ring.is_empty());Implementations§
Source§impl EventRingBuffer
impl EventRingBuffer
Sourcepub const DEFAULT_CAPACITY: usize = 1_024usize
pub const DEFAULT_CAPACITY: usize = 1_024usize
Default ring buffer capacity.
Sourcepub fn with_default_capacity() -> Self
pub fn with_default_capacity() -> Self
Create a new ring buffer with the default capacity (1024).
Sourcepub fn push(&mut self, event: FabricEvent)
pub fn push(&mut self, event: FabricEvent)
Push an event into the ring buffer.
If the buffer is full, the oldest event is overwritten.
Sourcepub fn iter(&self) -> EventRingIter<'_> ⓘ
pub fn iter(&self) -> EventRingIter<'_> ⓘ
Iterate over stored events in order (oldest first).
Sourcepub fn drain(&mut self) -> Vec<FabricEvent>
pub fn drain(&mut self) -> Vec<FabricEvent>
Drain all events from the buffer, returning them in order (oldest first).
The buffer is empty after this call.
Trait Implementations§
Source§impl EventSink for EventRingBuffer
impl EventSink for EventRingBuffer
Source§fn emit(&self, event: &FabricEvent)
fn emit(&self, event: &FabricEvent)
Consume an event. Implementations should not block.
Auto Trait Implementations§
impl Freeze for EventRingBuffer
impl RefUnwindSafe for EventRingBuffer
impl Send for EventRingBuffer
impl Sync for EventRingBuffer
impl Unpin for EventRingBuffer
impl UnwindSafe for EventRingBuffer
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