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>
impl<D: AsRef<[u8]> + Clone + Send> BufferedBody<D>
pub fn new(chunks: impl IntoIterator<Item = D>) -> Self
Sourcepub fn read_chunk(&mut self) -> Option<D>
pub fn read_chunk(&mut self) -> Option<D>
Read immediately available memory without scheduling an operation.
Sourcepub fn buffered(&self) -> Self
pub fn buffered(&self) -> Self
A buffered representation with an independent cursor at the beginning.
Sourcepub fn write(&mut self, chunk: D)
pub fn write(&mut self, chunk: D)
Append a chunk, including after earlier chunks have been read or closed.
pub fn clear(&mut self)
Trait Implementations§
Source§impl<D: Clone> Clone for BufferedBody<D>
impl<D: Clone> Clone for BufferedBody<D>
Source§impl<D: Debug> Debug for BufferedBody<D>
impl<D: Debug> Debug for BufferedBody<D>
Source§impl<D> Default for BufferedBody<D>
impl<D> Default for BufferedBody<D>
Source§impl<D: AsRef<[u8]> + Clone + Send> ReadableBody for BufferedBody<D>
impl<D: AsRef<[u8]> + Clone + Send> ReadableBody for BufferedBody<D>
type Error = Cancelled
Source§fn may_have_trailers(&self) -> bool
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
fn is_ready(&self) -> bool
Whether another read can proceed without waiting for produced data. Read more
Source§fn is_empty(&self) -> bool
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>
fn length(&self) -> Option<u64>
Total representation length, independent of the current read position.
fn is_rewindable(&self) -> bool
Source§fn close(&mut self, _error: Option<Self::Error>)
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>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more