Skip to main content

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. put returns CapacityExceeded only if the live bytes would exceed N.

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 (appended but not yet consumed).
§

fn consume(&mut self, n: usize)

Marks the leading n filled bytes as consumed. Read more
§

fn truncate(&mut self, len: usize)

Keeps the leading len filled bytes and drops the rest. Read more
§

fn clear(&mut self)

Drops all buffered bytes. Read more
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

fn default() -> Self

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

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

§

type Error = CapacityExceeded

Error returned when the sink cannot take more bytes.
§

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

Appends bytes. Read more
§

fn reserve(&mut self, additional: usize) -> Result<(), CapacityExceeded>

Makes room for additional more bytes, so that putting them does not fail or reallocate. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for ArrayBuffer<N>
where [u8; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for ArrayBuffer<N>
where [u8; N]: RefUnwindSafe,

§

impl<const N: usize> Send for ArrayBuffer<N>
where [u8; N]: Send,

§

impl<const N: usize> Sync for ArrayBuffer<N>
where [u8; N]: Sync,

§

impl<const N: usize> Unpin for ArrayBuffer<N>
where [u8; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for ArrayBuffer<N>
where [u8; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for ArrayBuffer<N>
where [u8; N]: UnwindSafe,

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 = !

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.