ArrayBuffer

Struct ArrayBuffer 

pub struct ArrayBuffer<const N: usize> {
    buf: [u8; N],
    head: usize,
    tail: usize,
}
Expand description

A fixed-capacity ByteBuffer backed by an inline [u8; N].

The buffer for no_std/no-alloc targets: it never allocates and bounds the total buffered bytes to N. When the tail fills but space has been freed at the front, the live bytes are compacted down; only once N bytes are genuinely live does spare return CapacityExceeded.

N should be at least as large as the largest packet the client will accept or send plus room for any bytes of a following packet read in the same chunk.

Fields§

§buf: [u8; N]§head: usize

Start of the live region.

§tail: usize

One past the end of the live region.

Implementations§

§

impl<const N: usize> ArrayBuffer<N>

pub const fn new() -> Self

Creates an empty buffer.

Trait Implementations§

§

impl<const N: usize> ByteBuffer for ArrayBuffer<N>

§

fn filled(&self) -> &[u8]

The contiguous run of live bytes (fed/committed but not yet consumed).
§

fn spare(&mut self, len: usize) -> Result<&mut [u8], CapacityExceeded>

Reserves a contiguous, writable tail region of exactly len bytes. Read more
§

fn commit(&mut self, n: usize)

Commits the leading n bytes of the region returned by the preceding spare call, making them part of filled.
§

fn consume(&mut self, n: usize)

Marks the leading n filled bytes as consumed.
§

fn clear(&mut self)

Drops all buffered bytes. Read more
§

fn extend(&mut self, chunk: &[u8]) -> Result<(), CapacityExceeded>

Appends a known slice. Convenience over spare + commit for the read side. Read more
§

impl<const N: usize> Default for ArrayBuffer<N>

§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<const N: usize> UnwindSafe for ArrayBuffer<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, 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.