[][src]Struct chunked_bytes::loosely::ChunkedBytes

pub struct ChunkedBytes { /* fields omitted */ }

A non-contiguous buffer for efficient serialization of data structures.

A ChunkedBytes container has a staging buffer to coalesce small byte sequences of source data, and a queue of byte chunks split off the staging buffer that can be incrementally consumed by an output API such as an object implementing AsyncWrite. Once the number of bytes in the staging buffer reaches a certain configured chunk size, the buffer content is split off to form a new chunk.

This variant of the container does not enforce an upper limit on the size of contiguous chunks, being optimized for performance. If your application needs the sizes of the produced chunks to be capped, use strictly::ChunkedBytes instead.

Refer to the documentation on the methods available for ChunkedBytes, including the methods of traits Buf and BufMut, for details on working with this container.

Implementations

impl ChunkedBytes[src]

pub fn new() -> Self[src]

Creates a new ChunkedBytes container with the preferred chunk size set to a default value.

pub fn with_chunk_size_hint(chunk_size: usize) -> Self[src]

Creates a new ChunkedBytes container with the given chunk size to prefer.

pub fn with_profile(chunk_size: usize, chunking_capacity: usize) -> Self[src]

The fully detailed constructor for ChunkedBytes. The preferred chunk size is given in chunk_size, and an upper estimate of the number of chunks this container could be expected to have at any moment of time should be given in chunking_capacity. More chunks can still be held, but this may cause reallocations of internal data structures.

pub fn chunk_size_hint(&self) -> usize[src]

Returns the size this ChunkedBytes container uses as the threshold for splitting off complete chunks.

Note that the size of produced chunks may be larger or smaller than the configured value, due to the allocation strategy used internally by the implementation and also depending on the pattern of usage.

pub fn is_empty(&self) -> bool[src]

Returns true if the ChunkedBytes container has no complete chunks and the staging buffer is empty.

pub fn flush(&mut self)[src]

Splits any bytes that are currently in the staging buffer into a new complete chunk. If the staging buffer is empty, this method does nothing.

Most users should not need to call this method. It is called internally when needed by the methods that advance the writing position.

pub fn put_bytes(&mut self, chunk: Bytes)[src]

Appends a Bytes slice to the container without copying the data.

If chunk is empty, this method does nothing. Otherwise, if there are any bytes currently in the staging buffer, they are split to form a complete chunk. Next, the given slice is appended as the next chunk.

pub fn drain_chunks(&mut self) -> DrainChunks[src]

Returns an iterator that removes complete chunks from the ChunkedBytes container and yields the removed chunks as Bytes slice handles. This does not include bytes in the staging buffer.

The chunks are removed even if the iterator is dropped without being consumed until the end. It is unspecified how many chunks are removed if the DrainChunks value is not dropped, but the borrow it holds expires (e.g. due to std::mem::forget).

pub fn into_chunks(self) -> IntoChunks[src]

Consumes the ChunkedBytes container to produce an iterator over its chunks. If there are bytes in the staging buffer, they are yielded as the last chunk.

The memory allocated for IntoChunks may be slightly more than the ChunkedBytes container it consumes. This is an infrequent side effect of making the internal state efficient in general for iteration.

Trait Implementations

impl Buf for ChunkedBytes[src]

fn bytes(&self) -> &[u8][src]

Returns a slice of the bytes in the first extant complete chunk, or the bytes in the staging buffer if there are no unconsumed chunks.

It is more efficient to use bytes_vectored to gather all the disjoint slices for vectored output, as is done in many specialized implementations of the AsyncWrite::poll_write_buf method.

fn advance(&mut self, cnt: usize)[src]

Advances the reading position by cnt, dropping the Bytes references to any complete chunks that the position has been advanced past and then advancing the starting position of the first remaining chunk. If there are no complete chunks left, the reading position is advanced in the staging buffer, effectively removing the consumed bytes.

Panics

This function may panic when cnt > self.remaining().

fn bytes_vectored<'a>(&'a self, dst: &mut [IoSlice<'a>]) -> usize[src]

Fills dst sequentially with the slice views of the chunks, then the bytes in the staging buffer if any remain and there is another unfilled entry left in dst. Returns the number of IoSlice entries filled.

impl BufMut for ChunkedBytes[src]

fn bytes_mut(&mut self) -> &mut [MaybeUninit<u8>][src]

Returns a mutable slice of unwritten bytes available in the staging buffer, starting at the current writing position.

The length of the slice may be larger than the preferred chunk size due to the allocation strategy used internally by the implementation.

impl Debug for ChunkedBytes[src]

impl Default for ChunkedBytes[src]

impl Write for ChunkedBytes[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<B> BufExt for B where
    B: Buf + ?Sized
[src]

impl<B> BufMutExt for B where
    B: BufMut + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.