Skip to main content

ByteTap

Struct ByteTap 

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

A positional, non-blocking observer of bytes passing a point in the byte layer. See the module docs.

Implementations§

Source§

impl ByteTap

Source

pub fn new(point: TapPoint, capacity: usize) -> Self

Create a tap at point with a ring bounded to capacity items.

capacity is a hard cap independent of how fast ByteTap::record is called or how slowly ByteTap::poll drains it — see the module docs’s non-blocking trade. Panics if capacity == 0, which would make every recorded item lost immediately and is almost certainly a construction mistake rather than an intended tap.

Source

pub fn point(&self) -> TapPoint

Where this tap sits in the byte pipeline.

Source

pub fn capacity(&self) -> usize

The fixed ring bound this tap was constructed with.

Source

pub fn len(&self) -> usize

Items currently buffered, awaiting ByteTap::poll. Never exceeds ByteTap::capacity — useful for a caller that wants to watch a tap’s backlog before it starts lagging.

Source

pub fn is_empty(&self) -> bool

true if no items are currently buffered.

Source

pub fn record(&mut self, bytes: Bytes, at: Timestamp)

Producer side: record one observed byte unit with its arrival time.

Never blocks, never errors, never grows the ring past ByteTap::capacity. When the ring is already full, the oldest buffered item is evicted to make room and a skip is recorded for the next ByteTap::poll to report — the producer always completes in O(1) regardless of whether anything has ever called poll. See the module docs for why this is the correct trade and what it costs a slow consumer.

Source

pub fn poll(&mut self) -> Option<TapItem>

Consumer side: pull the next observed item.

Returns TapItem::Lagged first if any items were evicted since the last poll — a consumer cannot skip past it to reach the data that follows a gap. Returns None when the ring is empty and no loss is pending.

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.