Skip to main content

BufferedBody

Struct BufferedBody 

Source
pub struct BufferedBody<D = Vec<u8>> { /* private fields */ }
Expand description

An in-memory, replayable sequence of chunks.

Reads clone each chunk, following Socketry’s buffered body. The application chooses its owner: a Vec<u8> yields independent data, whereas an immutable shared owner can clone cheaply. Closing preserves the chunks for rewinding.

Implementations§

Source§

impl<D: AsRef<[u8]> + Clone + Send> BufferedBody<D>

Source

pub fn new(chunks: impl IntoIterator<Item = D>) -> Self

Source

pub fn chunks(&self) -> &[D]

All original chunks, including data already read.

Source

pub fn read_chunk(&mut self) -> Option<D>

Read immediately available memory without scheduling an operation.

Source

pub fn buffered(&self) -> Self

A buffered representation with an independent cursor at the beginning.

Source

pub fn write(&mut self, chunk: D)

Append a chunk, including after earlier chunks have been read or closed.

Source

pub fn clear(&mut self)

Trait Implementations§

Source§

impl<D: Clone> Clone for BufferedBody<D>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: Debug> Debug for BufferedBody<D>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<D> Default for BufferedBody<D>

Source§

fn default() -> Self

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

impl<D: AsRef<[u8]> + Clone + Send> From<D> for BufferedBody<D>

Source§

fn from(chunk: D) -> Self

Converts to this type from the input type.
Source§

impl<D: AsRef<[u8]> + Clone + Send> ReadableBody for BufferedBody<D>

Source§

type Data = D

Application data, without imposing completion-I/O buffer requirements.
Source§

type Error = Cancelled

Source§

fn may_have_trailers(&self) -> bool

Whether this body can emit trailing headers. HTTP/1 needs this before reading to choose chunked framing, even when the data length is known. Returning false promises that no Headers frame will be produced.
Source§

fn is_ready(&self) -> bool

Whether another read can proceed without waiting for produced data. Read more
Source§

fn is_empty(&self) -> bool

Whether no unread payload frames remain. False can mean unknown; an open queue with no frames is not exhausted. This does not suppress read errors.
Source§

fn length(&self) -> Option<u64>

Total representation length, independent of the current read position.
Source§

fn is_rewindable(&self) -> bool

Source§

fn rewind(&mut self) -> bool

Restore the read position when supported, reporting success.
Source§

fn close(&mut self, _error: Option<Self::Error>)

Abandon further application reads, optionally reporting their failure. Read more
Source§

async fn read( &mut self, cancellation: &Cancellation, ) -> Result<BodyFrame<Self::Data>, Self::Error>

Read one owned frame. Pre-cancellation prevents consumption. The caller stops after frame.is_end(); subsequent reads return BodyFrame::End. Headers occur at most once, after all data. Dropping a pending read is not transport retirement, and must not lose an unreturned queued frame.

Auto Trait Implementations§

§

impl<D> Freeze for BufferedBody<D>
where Chunks<D>: Freeze,

§

impl<D> RefUnwindSafe for BufferedBody<D>
where Chunks<D>: RefUnwindSafe,

§

impl<D> Send for BufferedBody<D>
where Chunks<D>: Send,

§

impl<D> Sync for BufferedBody<D>
where Chunks<D>: Sync,

§

impl<D> Unpin for BufferedBody<D>
where Chunks<D>: Unpin,

§

impl<D> UnsafeUnpin for BufferedBody<D>
where Chunks<D>: UnsafeUnpin,

§

impl<D> UnwindSafe for BufferedBody<D>
where Chunks<D>: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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.