rustls::vecbuf

Struct ChunkVecBuffer

Source
pub(crate) struct ChunkVecBuffer {
    prefix_used: usize,
    chunks: VecDeque<Vec<u8>>,
    limit: Option<usize>,
}
Expand description

This is a byte buffer that is built from a deque of byte vectors.

This avoids extra copies when appending a new byte vector, at the expense of more complexity when reading out.

Fields§

§prefix_used: usize

How many bytes have been consumed in the first chunk.

Invariant: zero if chunks.is_empty() Invariant: 0 <= prefix_used < chunks[0].len()

§chunks: VecDeque<Vec<u8>>§limit: Option<usize>

The total upper limit (in bytes) of this object.

Implementations§

Source§

impl ChunkVecBuffer

Source

pub(crate) fn new(limit: Option<usize>) -> Self

Source

pub(crate) fn set_limit(&mut self, new_limit: Option<usize>)

Sets the upper limit on how many bytes this object can store.

Setting a lower limit than the currently stored data is not an error.

A None limit is interpreted as no limit.

Source

pub(crate) fn is_empty(&self) -> bool

If we’re empty

Source

pub(crate) fn len(&self) -> usize

How many bytes we’re storing

Source

pub(crate) fn apply_limit(&self, len: usize) -> usize

For a proposed append of len bytes, how many bytes should we actually append to adhere to the currently set limit?

Source

pub(crate) fn append(&mut self, bytes: Vec<u8>) -> usize

Take and append the given bytes.

Source

pub(crate) fn pop(&mut self) -> Option<Vec<u8>>

Take one of the chunks from this object.

This function returns None if the object is_empty.

Source

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

Inspect the first chunk from this object.

Source§

impl ChunkVecBuffer

Source

pub(crate) fn is_full(&self) -> bool

Source

pub(crate) fn append_limited_copy( &mut self, payload: OutboundChunks<'_>, ) -> usize

Append a copy of bytes, perhaps a prefix if we’re near the limit.

Source

pub(crate) fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Read data out of this object, writing it into buf and returning how many bytes were written there.

Source

pub(crate) fn consume_first_chunk(&mut self, used: usize)

Source

fn consume(&mut self, used: usize)

Source

pub(crate) fn write_to(&mut self, wr: &mut dyn Write) -> Result<usize>

Read data out of this object, passing it wr

Source

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

Returns the first contiguous chunk of data, or None if empty.

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.