Skip to main content

RingBufferCapture

Struct RingBufferCapture 

Source
pub struct RingBufferCapture { /* private fields */ }
Expand description

In-memory packet capture with optional ring-buffer eviction.

Prefer crate::BusCapture for most use cases — it includes statistics counters and supports stats-only, bounded, and unbounded modes. Use RingBufferCapture only when you need a standalone ring buffer without statistics tracking.

§Example

use oms_modbus::monitor::RingBufferCapture;
let capture = RingBufferCapture::new(10_000); // bounded, 10k records

Implementations§

Source§

impl RingBufferCapture

Source

pub fn new(capacity: usize) -> Self

Create a bounded ring buffer with the given capacity. When full, oldest records are evicted.

capacity is clamped to a minimum of 1. Passing 0 is equivalent to passing 1 — a single-record buffer.

Source

pub fn unbounded() -> Self

Create an unbounded capture that never drops records. Use with caution — memory grows indefinitely.

Source

pub fn len(&self) -> usize

Number of records currently buffered.

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty.

Source

pub fn dropped(&self) -> u64

Number of records dropped due to buffer overflow (bounded mode only).

Source

pub fn drain(&self) -> Vec<PacketRecord>

Drain all records in chronological order. Clears the buffer.

Source

pub fn snapshot(&self) -> Vec<PacketRecord>

Take a snapshot without clearing. Records are in chronological order.

Clones all records under the lock. For large buffers in hot paths, prefer Self::drain which swaps the buffer and releases the lock immediately.

Source

pub fn set_unbounded(&self)

Switch to unbounded mode (existing records preserved).

Source

pub fn set_bounded(&self)

Switch to bounded mode, stopping unbounded growth.

Capacity is fixed at construction time; this only prevents the ring buffer from growing without bound. Use RingBufferCapture::new to create a capture with a specific capacity.

Trait Implementations§

Source§

impl Default for RingBufferCapture

Source§

fn default() -> Self

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

impl WireTap for RingBufferCapture

Source§

fn on_write(&self, bytes: &[u8], ts: u64)

Bytes successfully written to the transport. Called once per poll_write that returns Ok(n) with n > 0.
Source§

fn on_read(&self, bytes: &[u8], ts: u64)

Bytes successfully read from the transport. Called once per poll_read that returns Ready(Ok(())) with new data.
Source§

fn on_error(&self, bytes: &[u8], error: &str, ts: u64)

Read returned an error, but partial data may have been received. Called when poll_read returns Ready(Err(e)) and the read buffer contains bytes that arrived before the error.

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.