EventRingBuffer

Struct EventRingBuffer 

Source
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

Source

pub const DEFAULT_CAPACITY: usize = 1_024usize

Default ring buffer capacity.

Source

pub fn new(capacity: usize) -> Self

Create a new ring buffer with the given capacity.

Source

pub fn with_default_capacity() -> Self

Create a new ring buffer with the default capacity (1024).

Source

pub fn push(&mut self, event: FabricEvent)

Push an event into the ring buffer.

If the buffer is full, the oldest event is overwritten.

Source

pub fn len(&self) -> usize

Number of events currently stored.

Source

pub fn is_empty(&self) -> bool

Whether the buffer is empty.

Source

pub fn capacity(&self) -> usize

Capacity of the ring buffer.

Source

pub fn iter(&self) -> EventRingIter<'_>

Iterate over stored events in order (oldest first).

Source

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

Source§

fn emit(&self, event: &FabricEvent)

Consume an event. Implementations should not block.

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.