Skip to main content

ChannelBuffer

Enum ChannelBuffer 

Source
pub enum ChannelBuffer {
    Lossy(RingBuffer),
    Reliable(Queue),
}
Expand description

A channel buffer that is either lossy (RingBuffer) or reliable (Queue).

The push method returns Ok(usize) — the number of older frames evicted (always 0 for reliable channels). Use push_checked for a richer PushOutcome.

Variants§

§

Lossy(RingBuffer)

Lossy mode: oldest frames are silently dropped when the byte budget is exceeded.

§

Reliable(Queue)

Reliable mode: pushes are rejected with Error::ChannelFull when the byte budget is exceeded.

Implementations§

Source§

impl ChannelBuffer

Source

pub fn push(&self, frame: &[u8]) -> Result<usize, Error>

Push a frame into the channel.

For lossy channels, returns Ok(usize) — the number of older frames evicted to make room (or 0 if the frame was too large and silently discarded). For reliable channels, returns Ok(0) on success or Err(Error::ChannelFull) if the byte budget would be exceeded.

Source

pub fn push_checked(&self, frame: &[u8]) -> Result<PushOutcome, Error>

Push a frame with a richer outcome report.

Like push, but returns PushOutcome for lossy channels, distinguishing between accepted frames and frames that were too large to ever fit.

Source

pub fn drain_all(&self) -> Vec<u8>

Drain all buffered frames into a single binary blob and clear the buffer.

The wire format is identical for both variants — see RingBuffer::drain_all for details.

Source

pub fn try_pop(&self) -> Option<Vec<u8>>

Read one frame from the front of the buffer (FIFO).

Returns None if the buffer is empty.

Source

pub fn frame_count(&self) -> usize

Number of frames currently buffered.

Source

pub fn bytes_used(&self) -> usize

Number of bytes currently used (including per-frame length prefixes).

Source

pub fn clear(&self)

Clear all buffered frames.

Source

pub fn is_ordered(&self) -> bool

Returns true if this channel uses reliable (guaranteed-delivery) buffering.

Trait Implementations§

Source§

impl Debug for ChannelBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.