Skip to main content

RingBuffer

Struct RingBuffer 

Source
pub struct RingBuffer<const N: usize> { /* private fields */ }
Expand description

Fixed-capacity byte ring buffer for variable-length packets.

Stores packets contiguously with a 2-byte length prefix. When a packet doesn’t fit between the write cursor and the buffer end, the gap is skipped and the packet wraps to position 0. Worst case wastes MTU bytes once — same as one Deque slot — but typical utilization is much better since small packets pack tightly.

When the ring is full, push returns false and the packet is dropped (tail-drop policy).

Implementations§

Source§

impl<const N: usize> RingBuffer<N>

Source

pub const fn new() -> Self

Create a new empty ring buffer.

Source

pub fn push(&mut self, data: &[u8]) -> bool

Push a packet into the ring. Returns false if full.

Source

pub fn front(&self) -> Option<&[u8]>

Peek at the front packet without removing it.

Source

pub fn pop(&mut self)

Remove the front packet.

Source

pub fn len(&self) -> usize

Number of packets currently stored.

Source

pub fn is_empty(&self) -> bool

Returns true if the ring contains no packets.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for RingBuffer<N>

§

impl<const N: usize> RefUnwindSafe for RingBuffer<N>

§

impl<const N: usize> Send for RingBuffer<N>

§

impl<const N: usize> Sync for RingBuffer<N>

§

impl<const N: usize> Unpin for RingBuffer<N>

§

impl<const N: usize> UnsafeUnpin for RingBuffer<N>

§

impl<const N: usize> UnwindSafe for RingBuffer<N>

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

Source§

type Output = T

Should always be Self
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.