Skip to main content

BusCapture

Struct BusCapture 

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

Unified bus capture — WireTap implementation with three storage modes.

Wrap in Arc to share between client and test code:

§Examples

use oms_modbus::*;
use std::sync::Arc;

let cap = Arc::new(BusCapture::unbounded());
let opts = ClientOptions::default().with_tap(cap.clone());

Implementations§

Source§

impl BusCapture

Source

pub fn stats_only() -> Self

Statistics only — no recording, atomic counters only. Zero memory allocation beyond the counters themselves.

Source

pub fn unbounded() -> Self

Full recording — stores every record, never evicts.

Source

pub fn bounded(capacity: usize) -> Self

Bounded ring buffer — oldest records evicted when full. Records are returned in chronological order by Self::drain and Self::snapshot.

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

Source

pub fn count_requests(&self) -> u64

Source

pub fn count_responses(&self) -> u64

Source

pub fn count_errors(&self) -> u64

Source

pub fn dropped(&self) -> u64

Source

pub fn reset_stats(&self)

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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

Drain all records in chronological order. Stats are NOT reset.

Source

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

Snapshot without clearing. Records are in chronological order.

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

Trait Implementations§

Source§

impl WireTap for BusCapture

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.