GrowBuffer

Struct GrowBuffer 

pub struct GrowBuffer {
    buf: Vec<u8>,
    head: usize,
    spare: usize,
}
Available on crate feature alloc only.
Expand description

A heap-backed ByteBuffer that grows as needed.

Consumed bytes are reclaimed lazily on the next reservation, so draining many packets out of one read does not repeatedly shift the tail. It never returns CapacityExceeded; per-packet bounds come from the reader’s or writer’s set_max_packet_size instead.

Fields§

§buf: Vec<u8>§head: usize

Offset of the first unconsumed byte.

§spare: usize

Length of the tail region handed out by the last spare and not yet committed.

Implementations§

§

impl GrowBuffer

pub const fn new() -> Self

Creates an empty buffer.

pub fn with_capacity(capacity: usize) -> Self

Creates an empty buffer preallocating capacity bytes.

pub fn take(&mut self) -> Vec<u8>

Takes the live bytes as an owned Vec, leaving the buffer empty.

Lets an I/O driver hand a batch of encoded packets to a writer task by value without copying when the consumed prefix is empty.

fn reclaim(&mut self)

Trait Implementations§

§

impl ByteBuffer for GrowBuffer

§

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 extend(&mut self, chunk: &[u8]) -> Result<(), CapacityExceeded>

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

fn consume(&mut self, n: usize)

Marks the leading n filled bytes as consumed.
§

fn clear(&mut self)

Drops all buffered bytes. Read more
§

impl Default for GrowBuffer

§

fn default() -> Self

Returns the “default value” for a type. 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.