Skip to main content

ReadableBody

Trait ReadableBody 

Source
pub trait ReadableBody: Send {
    type Data: AsRef<[u8]> + Send;
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn close(&mut self, error: Option<Self::Error>);
    fn read(
        &mut self,
        cancellation: &Cancellation,
    ) -> impl Future<Output = Result<BodyFrame<Self::Data>, Self::Error>> + Send;

    // Provided methods
    fn is_ready(&self) -> bool { ... }
    fn is_empty(&self) -> bool { ... }
    fn length(&self) -> Option<u64> { ... }
    fn may_have_trailers(&self) -> bool { ... }
    fn is_rewindable(&self) -> bool { ... }
    fn rewind(&mut self) -> bool { ... }
}
Expand description

Protocol-independent body observations and lifecycle.

No observation performs I/O or requires a scheduler. Readiness, exhaustion, known representation length and rewindability are independent properties.

Required Associated Types§

Source

type Data: AsRef<[u8]> + Send

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

Source

type Error: Error + Send + Sync + 'static

Required Methods§

Source

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

Abandon further application reads, optionally reporting their failure.

This synchronous operation does not guarantee asynchronous resource retirement. An I/O-backed implementation must leave cleanup with an explicit resource/driver owner. Cancelling or dropping a read does not prove that backend access ended, nor that a connection can be reused.

Source

fn read( &mut self, cancellation: &Cancellation, ) -> impl Future<Output = Result<BodyFrame<Self::Data>, Self::Error>> + Send

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.

Provided Methods§

Source

fn is_ready(&self) -> bool

Whether another read can proceed without waiting for produced data.

This is a conservative batching hint. Terminal completion/error can also be ready. It does not promise that an I/O operation will finish in one poll.

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 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_rewindable(&self) -> bool

Source

fn rewind(&mut self) -> bool

Restore the read position when supported, reporting success.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<R: ReadableBody + ?Sized> ReadableBody for &mut R

Source§

type Data = <R as ReadableBody>::Data

Source§

type Error = <R as ReadableBody>::Error

Source§

fn is_ready(&self) -> bool

Source§

fn is_empty(&self) -> bool

Source§

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

Source§

fn may_have_trailers(&self) -> bool

Source§

fn is_rewindable(&self) -> bool

Source§

fn rewind(&mut self) -> bool

Source§

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

Source§

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

Implementors§