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§
Sourcetype Data: AsRef<[u8]> + Send
type Data: AsRef<[u8]> + Send
Application data, without imposing completion-I/O buffer requirements.
type Error: Error + Send + Sync + 'static
Required Methods§
Sourcefn close(&mut self, error: Option<Self::Error>)
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.
Sourcefn read(
&mut self,
cancellation: &Cancellation,
) -> impl Future<Output = Result<BodyFrame<Self::Data>, Self::Error>> + Send
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§
Sourcefn is_ready(&self) -> bool
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.
Sourcefn 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.
Sourcefn length(&self) -> Option<u64>
fn length(&self) -> Option<u64>
Total representation length, independent of the current read position.
Sourcefn 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.
fn is_rewindable(&self) -> bool
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".